Sfoglia il codice sorgente

1.修复SDCycleScrollView 滚动bug

huangxiaodong 1 anno fa
parent
commit
b64380a5b1

+ 32 - 5
创维盒子/Pods/SDCycleScrollView/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m

@@ -684,17 +684,44 @@ NSString * const ID = @"SDCycleScrollViewCell";
     }
 }
 
-- (void)makeScrollViewScrollToIndex:(NSInteger)index{
+//- (void)makeScrollViewScrollToIndex:(NSInteger)index{
+//    if (self.autoScroll) {
+//        [self invalidateTimer];
+//    }
+//    if (0 == _totalItemsCount) return;
+//    
+//    [self scrollToIndex:(int)(_totalItemsCount * 0.5 + index)];
+//    
+//    if (self.autoScroll) {
+//        [self setupTimer];
+//    }
+//}
+
+//hxd add 20240516 by https://github.com/gsdios/SDCycleScrollView/issues/645
+-(void)makeScrollViewScrollToIndex:(NSInteger)index {
     if (self.autoScroll) {
-        [self invalidateTimer];
+    [self invalidateTimer];
     }
     if (0 == _totalItemsCount) return;
-    
-    [self scrollToIndex:(int)(_totalItemsCount * 0.5 + index)];
-    
+
+    [self makeScrollToIndex:index];
+
     if (self.autoScroll) {
         [self setupTimer];
     }
 }
 
+-(void)makeScrollToIndex:(NSInteger)targetIndex {
+    if (self.infiniteLoop) {
+        targetIndex = targetIndex%(_totalItemsCount/100);
+        targetIndex = _totalItemsCount * 0.5 + targetIndex;
+        if (targetIndex < [self currentIndex]) {
+        [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:(_totalItemsCount * 0.5 -1) inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
+        }
+    }else if (targetIndex >= _totalItemsCount){
+        return;
+    }
+    [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
+}
+
 @end