Procházet zdrojové kódy

1.修改图片预览索引不正确以及初始化时隐藏动画效果。

Pen Li před 7 roky
rodič
revize
bc83fc4dd6

+ 26 - 32
common/InfinitePhoto/Controller/RAPhotoPreviewController.m

@@ -20,6 +20,7 @@
 @property (nonatomic,assign) NSUInteger offset;
 
 @property (nonatomic,assign) BOOL hideNavigationBar;
+@property (nonatomic,assign) BOOL initialized;
 
 @end
 
@@ -40,7 +41,8 @@
         items = [tmpArr copy];
         vc.photos = items;
     }
-    vc.offset = 0;
+    vc.offset = offset;
+    vc.currentIndex = 0;
     
     return vc;
 }
@@ -56,29 +58,26 @@
     
     self.indicator.layer.cornerRadius = 20;
     self.indicator.layer.masksToBounds = YES;
-    
     self.previewContainer.pagingEnabled = YES;
-    NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
-    self.indicator.text = offset;
-   
     self.hideNavigationBar = self.navigationController.isNavigationBarHidden;
-    
     self.navigationController.navigationBarHidden = YES;
-}
-
-- (void)viewWillAppear:(BOOL)animated {
-    [super viewWillAppear:animated];
+    
+    [self updateIndicator];
 }
 
 - (void)viewDidLayoutSubviews {
     [super viewDidLayoutSubviews];
 
-   [self.previewContainer setContentOffset:CGPointMake((self.currentIndex + 1) * CGRectGetWidth(self.previewContainer.frame), 0) animated:NO];
-
+   [self.previewContainer setContentOffset:CGPointMake((self.currentIndex + 1) * CGRectGetWidth(self.previewContainer.frame), 0) animated:YES];
 }
 
 - (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
+    
+    // 隐藏初始化时滚动效果
+    self.initialized = YES;
+    [self.previewContainer reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:self.currentIndex + 1 inSection:0]]];
+
 }
 
 - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
@@ -104,12 +103,6 @@
     // Dispose of any resources that can be recreated.
 }
 
-#pragma mark - Setter
-
-- (void)setOffset:(NSUInteger)offset {
-    [self setCurrentIndex:offset];
-}
-
 #pragma mark - FlowLayout Delegate
 
 - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
@@ -132,12 +125,13 @@
 
 - (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
 
-    NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
-    
-    PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
-    
-    id<RAPhotoItemDelegate> model = [self.photos objectAtIndex:idx];
-    preCell.model = model;
+    if (self.initialized) {
+        
+        NSUInteger idx = [self contentOffsetForIndexPath:indexPath];
+        PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
+        id<RAPhotoItemDelegate> model = [self.photos objectAtIndex:idx];
+        preCell.model = model;
+    }
 }
 
 - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
@@ -204,17 +198,17 @@
     return nil;
 }
 
-- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
-    
-    if (self.previewContainer != scrollView) {
-        
-    }
-}
-
 #pragma mark - Private
 
 - (void)updateIndicator {
-    NSString *offset = [NSString stringWithFormat:@"%lu / %lu",(unsigned long)self.currentIndex + 1,(unsigned long)self.photos.count];
+    
+    NSUInteger index = 0;
+    if (self.currentIndex < self.offset) {
+        index = (unsigned long)self.currentIndex + 1 + self.offset;
+    } else {
+        index = (unsigned long)self.currentIndex + 1 - self.offset;
+    }
+    NSString *offset = [NSString stringWithFormat:@"%lu / %lu",index,(unsigned long)self.photos.count];
     self.indicator.text = offset;
 }