SDCycleScrollView icon indicating copy to clipboard operation
SDCycleScrollView copied to clipboard

滚动到指定index接口在轮播图设置为无限循环的时候根本滚动不到指定的index

Open nattychao opened this issue 5 years ago • 1 comments

nattychao avatar Jan 29 '21 06:01 nattychao

简单的解决了,不喜勿要喷 重新写了个makeScrollToIndex:

  • (void)makeScrollViewScrollToIndex:(NSInteger)index { if (self.autoScroll) { [self invalidateTimer]; } if (0 == _totalItemsCount) return;

    [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:YES]; }

MingYik avatar Mar 23 '21 03:03 MingYik