Procházet zdrojové kódy

1.修改图片预览缩放之后状态不正确。

Pen Li před 7 roky
rodič
revize
9922f643fc

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

@@ -132,6 +132,12 @@
     preCell.model = model;
 }
 
+- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
+    
+    PhotoPreviewCell *preCell = (PhotoPreviewCell *)cell;
+    [preCell reset];
+}
+
 #pragma mark - CollectionView DataSource
 
 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
@@ -151,30 +157,34 @@
 #pragma mark - ScrollView Delegate
 
 - (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;
+    if (scrollView == self.previewContainer) {
+        
+        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;
+            }
+            
+            [self updateIndicator];
         } else {
-            self.currentIndex = idxi - 1;
+            
         }
-
-        [self updateIndicator];
-    } else {
-
-    }
-    
-    if (idxi == 0) {
-        [self scrollToIndex:self.photos.count];
-    }
-    
-    if (idxi == self.photos.count + 1) {
-        [self scrollToIndex:1];
+        
+        if (idxi == 0) {
+            [self scrollToIndex:self.photos.count];
+        }
+        
+        if (idxi == self.photos.count + 1) {
+            [self scrollToIndex:1];
+        }
+        
     }
     
 }

+ 2 - 0
common/InfinitePhoto/View/PhotoPreviewCell.h

@@ -17,4 +17,6 @@
 
 @property (nonatomic,strong) id<RAPhotoItemDelegate> model;
 
+- (void)reset;
+
 @end

+ 8 - 4
common/InfinitePhoto/View/PhotoPreviewCell.m

@@ -27,16 +27,20 @@
     }
 }
 
-- (void)prepareForReuse {
-    [super prepareForReuse];
-
-    
+- (void)reset {
     UIScrollView *sc = self.scrollView;
     sc.zoomScale = 1;
     sc.contentSize = CGSizeZero;
     sc.contentOffset = CGPointZero;
 }
 
+- (void)prepareForReuse {
+    [super prepareForReuse];
+
+    [self reset];
+    self.model = nil;
+}
+
 - (void)layoutSubviews {
     [super layoutSubviews];