Просмотр исходного кода

1.修改NPD Model Detail预览。

Pen Li 9 лет назад
Родитель
Сommit
0b83c2b17a

BIN
RedAnt ERP Mobile/RedAnt ERP Mobile.xcworkspace/xcuserdata/macmini1.xcuserdatad/UserInterfaceState.xcuserstate


+ 11 - 8
RedAnt ERP Mobile/common/Functions/modelDetail/DetailHeaderCell.m

@@ -1157,14 +1157,10 @@
 
 -(void)photoStackView:(PhotoStackView *)photoStackView didSelectPhotoAtIndex:(NSUInteger)index {
     DebugLog(@"selected %lu", (unsigned long)index);
- /*
-    ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
-    preVC.content = self.stack_contents;
-    UIViewController *superVC= [RAUtils getViewController:self];
-    [superVC.navigationController pushViewController:preVC animated:true];
-    return;
-   */
-    NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%d",index]];
+ 
+   
+  
+    NSDictionary* item= self.stack_contents[[NSString stringWithFormat:@"item_%ld",index]];
     
     if([item[@"type"] isEqualToString:@"video"])
     {
@@ -1195,6 +1191,13 @@
         self.playerView.webView.allowsPictureInPictureMediaPlayback=false;
         self.playerView.hidden=false;
         
+        return;
+    } else {
+        ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
+        preVC.content = self.stack_contents;
+        preVC.currentIndex = index;
+        UIViewController *superVC= [RAUtils getViewController:self];
+        [superVC.navigationController pushViewController:preVC animated:true];
         return;
     }
     

+ 1 - 1
RedAnt ERP Mobile/iSales-NPD/PhotoList/Controller/ContentPreviewController.h

@@ -12,6 +12,6 @@
 
 @property (nonatomic,strong) NSDictionary *content;
 
-@property (nonatomic,assign) NSUInteger currentIndex;
+- (void)setOffset:(NSUInteger)offset;
 
 @end

+ 61 - 9
RedAnt ERP Mobile/iSales-NPD/PhotoList/Controller/ContentPreviewController.m

@@ -16,12 +16,13 @@
 
 @interface ContentPreviewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
 
+@property (nonatomic,assign) NSUInteger currentIndex;
 @property (strong, nonatomic) IBOutlet UILabel *indicator;
 @property (strong, nonatomic) IBOutlet UICollectionView *previewContainer;
 
 @property (nonatomic,strong) NSArray *photos;
 
-@property (nonatomic,strong) UIScrollView *mask;
+@property (nonatomic,strong) UIView *mask;
 
 @property (nonatomic,assign) BOOL hideNavigationBar;
 
@@ -59,6 +60,8 @@
     
     self.navigationController.navigationBarHidden = YES;
     
+    // 掩藏滚动
+    [self.view insertSubview:self.mask belowSubview:self.indicator];
 }
 
 - (void)viewDidLayoutSubviews {
@@ -73,6 +76,17 @@
 
 - (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
+    
+//    [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
+    
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        sleep(0.25);
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self.mask removeFromSuperview];
+            self.mask = nil;
+        });
+
+    });
 }
 
 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
@@ -90,15 +104,27 @@
     // Dispose of any resources that can be recreated.
 }
 
+- (UIView *)mask {
+    if (!_mask) {
+        _mask = [[UIView alloc] initWithFrame:self.view.bounds];
+        _mask.backgroundColor = [UIColor blackColor];
+    }
+    return _mask;
+}
+
 
 #pragma mark - Setter
 
-- (void)setCurrentIndex:(NSUInteger)currentIndex {
-    _currentIndex = currentIndex;
-    NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
-    self.indicator.text = offset;
+- (void)setOffset:(NSUInteger)offset {
+    [self setCurrentIndex:offset + 1];
 }
 
+//- (void)setCurrentIndex:(NSUInteger)currentIndex {
+//    _currentIndex = currentIndex;
+//    NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
+//    self.indicator.text = offset;
+//}
+
 #pragma mark - FlowLayout Delegate
 
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
@@ -122,6 +148,7 @@
 - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
 
     
+    
     NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
     NSString *type = [item objectForKey:@"type"];
     
@@ -130,13 +157,13 @@
         
         [self photoCell:preCell loadImage:item];
         
-//        preCell.scrollView.backgroundColor = [UIColor colorWithRed:(rand() % 255) / 255.0 green:(rand() % 255) / 255.0 blue:(rand() % 255) / 255.0 alpha:1];
+
         
     } else if ([type isEqualToString:@"video"]) {
         
         VideoPreviewCell *videoCell = (VideoPreviewCell *)cell;
         videoCell.item = item;
-//        videoCell.playerView.webView.backgroundColor = [UIColor colorWithRed:(rand() % 255) / 255.0 green:(rand() % 255) / 255.0 blue:(rand() % 255) / 255.0 alpha:1];
+
         
     }
 }
@@ -156,7 +183,19 @@
         
         VideoPreviewCell *videoCell = (VideoPreviewCell *)cell;
 
-        [videoCell.playerView pauseVideo];
+        [videoCell reset];
+    }
+}
+
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
+    NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
+    NSString *type = [item objectForKey:@"type"];
+    
+    if ([type isEqualToString:@"video"]) {
+        
+        VideoPreviewCell *videoCell = (VideoPreviewCell *)[collectionView cellForItemAtIndexPath:indexPath];
+        
+        [videoCell play];
     }
 }
 
@@ -181,7 +220,7 @@
     } else if ([type isEqualToString:@"video"]) {
         
         VideoPreviewCell *videoCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoPreviewCell" forIndexPath:indexPath];
-        videoCell.playerView.webView.backgroundColor = [UIColor blackColor];
+
         return videoCell;
     }
     
@@ -192,11 +231,13 @@
 
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
     if (scrollView == self.previewContainer) {
+
         CGFloat x = scrollView.contentOffset.x / scrollView.frame.size.width;
         int idx = (int)x;
         if (idx == x) {
             if (self.currentIndex != idx) {
                 self.currentIndex = idx;
+                
             }
         }
     }
@@ -219,6 +260,17 @@
 
 #pragma mark - Private
 
+- (NSUInteger)contentOffsetForIndexPath:(NSIndexPath *)indexPath {
+    NSUInteger idx = indexPath.row;
+    if (idx == 0) {
+        idx = self.photos.count - 1;
+    }else if (idx == self.photos.count + 1) {
+        idx = 0;
+    } else {
+        idx = idx - 1;
+    }
+    return idx;
+}
 
 - (void) photoCell:(PhotoPreviewCell *)cell loadImage:(NSDictionary *)item_json {
     

+ 10 - 0
RedAnt ERP Mobile/iSales-NPD/PhotoList/Storyboard/PhotoList.storyboard

@@ -90,17 +90,26 @@
                                                     <rect key="frame" x="0.0" y="-0.33333333333331439" width="414" height="735.33333333333326"/>
                                                     <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
                                                 </view>
+                                                <imageView contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="play" translatesAutoresizingMaskIntoConstraints="NO" id="Pgl-ZY-yIF">
+                                                    <rect key="frame" x="0.0" y="-0.33333333333331439" width="414" height="735.33333333333326"/>
+                                                    <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
+                                                </imageView>
                                             </subviews>
                                         </view>
                                         <color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
                                         <constraints>
+                                            <constraint firstItem="Pgl-ZY-yIF" firstAttribute="centerX" secondItem="fb9-eB-NDG" secondAttribute="centerX" id="1QL-c6-3dR"/>
+                                            <constraint firstItem="Pgl-ZY-yIF" firstAttribute="width" secondItem="fb9-eB-NDG" secondAttribute="width" id="492-Xq-8Dy"/>
                                             <constraint firstItem="g1h-px-8Fa" firstAttribute="centerY" secondItem="fb9-eB-NDG" secondAttribute="centerY" id="EEY-c6-vl9"/>
                                             <constraint firstItem="g1h-px-8Fa" firstAttribute="height" secondItem="fb9-eB-NDG" secondAttribute="height" id="SKL-jo-Lzt"/>
+                                            <constraint firstItem="Pgl-ZY-yIF" firstAttribute="centerY" secondItem="fb9-eB-NDG" secondAttribute="centerY" id="YwR-9C-HfW"/>
+                                            <constraint firstItem="Pgl-ZY-yIF" firstAttribute="height" secondItem="fb9-eB-NDG" secondAttribute="height" id="eeM-vX-WIb"/>
                                             <constraint firstItem="g1h-px-8Fa" firstAttribute="centerX" secondItem="fb9-eB-NDG" secondAttribute="centerX" id="h5h-8v-rGk"/>
                                             <constraint firstItem="g1h-px-8Fa" firstAttribute="width" secondItem="fb9-eB-NDG" secondAttribute="width" id="k9d-ie-GeL"/>
                                         </constraints>
                                         <size key="customSize" width="414" height="735"/>
                                         <connections>
+                                            <outlet property="VideoImageView" destination="Pgl-ZY-yIF" id="tkf-t3-BNf"/>
                                             <outlet property="playerView" destination="g1h-px-8Fa" id="Ydw-01-j1F"/>
                                         </connections>
                                     </collectionViewCell>
@@ -157,5 +166,6 @@
     </scenes>
     <resources>
         <image name="iv_close" width="32" height="32"/>
+        <image name="play" width="350" height="350"/>
     </resources>
 </document>

+ 4 - 0
RedAnt ERP Mobile/iSales-NPD/PhotoList/View/VideoPreviewCell.h

@@ -14,5 +14,9 @@
 @property (nonatomic,strong) NSDictionary *item;
 
 @property (strong, nonatomic) IBOutlet YTPlayerView *playerView;
+@property (strong, nonatomic) IBOutlet UIImageView *VideoImageView;
+
+- (void)reset;
+- (void)play;
 
 @end

+ 44 - 17
RedAnt ERP Mobile/iSales-NPD/PhotoList/View/VideoPreviewCell.m

@@ -8,27 +8,54 @@
 
 #import "VideoPreviewCell.h"
 
+@interface VideoPreviewCell ()
+
+@property (nonatomic,assign) BOOL isPlay;
+
+@end
+
 @implementation VideoPreviewCell
 
 - (void)setItem:(NSDictionary *)item {
     _item = item;
-    if (item) {
-        NSString* video_code=item[@"code"];
-
-        NSString* video_id=[self.playerView Embed2VID:video_code];
-        
-        NSDictionary *playerVars = @{
-                                     @"playsinline" : @1,
-                                     @"autoplay" : @(1),
-                                     @"rel":@0,
-                                     @"showinfo": @0,
-                                     @"modestbranding":@0,
-                                     @"enablejsapi":@1
-                                     };
-        
-        [self.playerView loadWithVideoId:video_id playerVars:playerVars];
-        
-        self.playerView.webView.allowsPictureInPictureMediaPlayback=false;
+
+}
+
+- (void)reset {
+
+    [self.playerView stopVideo];
+    self.item = nil;
+    self.isPlay = NO;
+    [self.contentView bringSubviewToFront:self.VideoImageView];
+    
+}
+
+- (void)play {
+    if (!self.isPlay) {
+        if (self.item) {
+            
+            [self.contentView bringSubviewToFront:self.playerView];
+            NSDictionary *item = self.item;
+            NSString* video_code=item[@"code"];
+            
+            NSString* video_id=[self.playerView Embed2VID:video_code];
+            
+            NSDictionary *playerVars = @{
+                                         @"playsinline" : @1,
+                                         @"autoplay" : @(1),
+                                         @"rel":@0,
+                                         @"showinfo": @0,
+                                         @"modestbranding":@0,
+                                         @"enablejsapi":@1
+                                         };
+            
+            [self.playerView loadWithVideoId:video_id playerVars:playerVars];
+            
+            self.playerView.webView.allowsPictureInPictureMediaPlayback=false;
+            
+            self.isPlay = YES;
+        }
+
     }
 }