Explorar el Código

1.修改NPD Model Detail图片预览,增加轮播效果。

Pen Li hace 9 años
padre
commit
2577614253

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


+ 2 - 1
RedAnt ERP Mobile/common/Functions/modelDetail/DetailHeaderCell.m

@@ -1195,7 +1195,8 @@
     } else {
     } else {
         ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
         ContentPreviewController *preVC = [[UIStoryboard storyboardWithName:@"PhotoList" bundle:nil] instantiateViewControllerWithIdentifier:@"ContentPreviewController"];
         preVC.content = self.stack_contents;
         preVC.content = self.stack_contents;
-        preVC.currentIndex = index;
+//        preVC.currentIndex = index;
+        [preVC setOffset:index];
         UIViewController *superVC= [RAUtils getViewController:self];
         UIViewController *superVC= [RAUtils getViewController:self];
         [superVC.navigationController pushViewController:preVC animated:true];
         [superVC.navigationController pushViewController:preVC animated:true];
         return;
         return;

+ 78 - 28
RedAnt ERP Mobile/iSales-NPD/PhotoList/Controller/ContentPreviewController.m

@@ -61,17 +61,18 @@
     self.navigationController.navigationBarHidden = YES;
     self.navigationController.navigationBarHidden = YES;
     
     
     // 掩藏滚动
     // 掩藏滚动
-    [self.view insertSubview:self.mask belowSubview:self.indicator];
+//    [self.view insertSubview:self.mask belowSubview:self.indicator];
 }
 }
 
 
 - (void)viewDidLayoutSubviews {
 - (void)viewDidLayoutSubviews {
     [super viewDidLayoutSubviews];
     [super viewDidLayoutSubviews];
 
 
     
     
-    if (self.currentIndex > 0) {
-        [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
-    }
+//    if (self.currentIndex > 0) {
+//        [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
+//    }
     
     
+    [self scrollToIndex:self.currentIndex + 1];
 }
 }
 
 
 - (void)viewDidAppear:(BOOL)animated {
 - (void)viewDidAppear:(BOOL)animated {
@@ -79,14 +80,14 @@
     
     
 //    [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:16 animated:YES];
 //    [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;
-        });
-
-    });
+//    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 {
 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
@@ -95,8 +96,12 @@
     [self.previewContainer.collectionViewLayout invalidateLayout];
     [self.previewContainer.collectionViewLayout invalidateLayout];
 
 
     // 重新布局Item位置
     // 重新布局Item位置
-    [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:32 animated:NO];
-    
+//    [self.previewContainer scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentIndex inSection:0] atScrollPosition:32 animated:NO];
+    [self scrollToIndex:self.currentIndex + 1];
+}
+
+- (BOOL)prefersStatusBarHidden {
+    return YES;
 }
 }
 
 
 - (void)didReceiveMemoryWarning {
 - (void)didReceiveMemoryWarning {
@@ -116,7 +121,7 @@
 #pragma mark - Setter
 #pragma mark - Setter
 
 
 - (void)setOffset:(NSUInteger)offset {
 - (void)setOffset:(NSUInteger)offset {
-    [self setCurrentIndex:offset + 1];
+    [self setCurrentIndex:offset];
 }
 }
 
 
 //- (void)setCurrentIndex:(NSUInteger)currentIndex {
 //- (void)setCurrentIndex:(NSUInteger)currentIndex {
@@ -149,7 +154,8 @@
 
 
     
     
     
     
-    NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
+    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+    NSDictionary *item = [self.photos objectAtIndex:idx];
     NSString *type = [item objectForKey:@"type"];
     NSString *type = [item objectForKey:@"type"];
     
     
     if ([type isEqualToString:@"image"]) {
     if ([type isEqualToString:@"image"]) {
@@ -170,7 +176,8 @@
 
 
 - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
 - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
     
     
-    NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
+    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+    NSDictionary *item = [self.photos objectAtIndex:idx];
     NSString *type = [item objectForKey:@"type"];
     NSString *type = [item objectForKey:@"type"];
     
     
     if ([type isEqualToString:@"image"]) {
     if ([type isEqualToString:@"image"]) {
@@ -188,7 +195,9 @@
 }
 }
 
 
 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-    NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
+    
+    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+    NSDictionary *item = [self.photos objectAtIndex:idx];
     NSString *type = [item objectForKey:@"type"];
     NSString *type = [item objectForKey:@"type"];
     
     
     if ([type isEqualToString:@"video"]) {
     if ([type isEqualToString:@"video"]) {
@@ -203,12 +212,14 @@
 #pragma mark - CollectionView DataSource
 #pragma mark - CollectionView DataSource
 
 
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
-    return self.photos.count;
+    return self.photos.count + 2;
 }
 }
 
 
 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
     
     
-    NSDictionary *item = [self.photos objectAtIndex:indexPath.row];
+    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+    
+    NSDictionary *item = [self.photos objectAtIndex:idx];
     NSString *type = [item objectForKey:@"type"];
     NSString *type = [item objectForKey:@"type"];
     
     
     if ([type isEqualToString:@"image"]) {
     if ([type isEqualToString:@"image"]) {
@@ -230,17 +241,47 @@
 #pragma mark - ScrollView Delegate
 #pragma mark - ScrollView Delegate
 
 
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
-    if (scrollView == self.previewContainer) {
+//    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;
+//                
+//            }
+//        }
+//    }
+}
 
 
-        CGFloat x = scrollView.contentOffset.x / scrollView.frame.size.width;
-        int idx = (int)x;
-        if (idx == x) {
-            if (self.currentIndex != idx) {
-                self.currentIndex = idx;
-                
-            }
+- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
+    CGFloat offsetX = scrollView.contentOffset.x;
+    float idxf = offsetX / CGRectGetWidth(scrollView.frame);
+    int idxi = (int)(offsetX / CGRectGetWidth(scrollView.frame));
+    
+    if (idxf == idxi) {
+        if (idxi == 0) {
+            self.currentIndex = self.photos.count - 1;
+        } else if (idxi == self.photos.count + 1) {
+            self.currentIndex = 0;
+        } else {
+            self.currentIndex = idxi - 1;
         }
         }
+        
+//        if (self.indicator) {
+//            self.indicator(self.currentIndex, self.photos.count);
+//        }
+        [self updateIndicator];
+    }
+    
+    if (idxi == 0) {
+        [self scrollToIndex:self.photos.count];
     }
     }
+    
+    if (idxi == self.photos.count + 1) {
+        [self scrollToIndex:1];
+    }
+    
 }
 }
 
 
 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
 - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
@@ -260,6 +301,11 @@
 
 
 #pragma mark - Private
 #pragma mark - Private
 
 
+- (void)updateIndicator {
+    NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
+    self.indicator.text = offset;
+}
+
 - (NSUInteger)contentOffsetForIndexPath:(NSIndexPath *)indexPath {
 - (NSUInteger)contentOffsetForIndexPath:(NSIndexPath *)indexPath {
     NSUInteger idx = indexPath.row;
     NSUInteger idx = indexPath.row;
     if (idx == 0) {
     if (idx == 0) {
@@ -272,6 +318,10 @@
     return idx;
     return idx;
 }
 }
 
 
+- (void)scrollToIndex:(NSUInteger)index { // 不会出现肉眼可见的滚动效果
+    self.previewContainer.contentOffset = CGPointMake(index * CGRectGetWidth(self.previewContainer.frame), 0);
+}
+
 - (void) photoCell:(PhotoPreviewCell *)cell loadImage:(NSDictionary *)item_json {
 - (void) photoCell:(PhotoPreviewCell *)cell loadImage:(NSDictionary *)item_json {
     
     
     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
     AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;