From 25ac410e424f3fa7c805db7838ce3715d439d4e2 Mon Sep 17 00:00:00 2001 From: houhui <403262655@qq.com> Date: Tue, 1 Dec 2020 11:33:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BD=AE=E6=92=ADview?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6=E4=B8=BA=E5=B0=8F=E6=95=B0=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E6=92=AD=E6=94=BE=E9=94=99=E4=B9=B1=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lib/SDCycleScrollView/SDCycleScrollView.m | 16 ++++++++++++---- SDCycleScrollView/ViewController.m | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m index 2ce019b9..664d55cd 100644 --- a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m +++ b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m @@ -150,6 +150,14 @@ - (void)setupMainView _mainView = mainView; } +- (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated { + + //在ipx上宽度为小数的时候会出现错乱的情况,所以不能使用 +// [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:YES]; + + //下面方法这样避免了轮播view宽度为小数的时候轮播错乱的情况 + [_mainView setContentOffset:CGPointMake(index*_flowLayout.itemSize.width, 0) animated:animated]; +} #pragma mark - properties @@ -442,11 +450,11 @@ - (void)scrollToIndex:(int)targetIndex if (targetIndex >= _totalItemsCount) { if (self.infiniteLoop) { targetIndex = _totalItemsCount * 0.5; - [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self scrollToItemAtIndex:targetIndex animated:NO]; } return; } - [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:YES]; + [self scrollToItemAtIndex:targetIndex animated:YES]; } - (int)currentIndex @@ -498,7 +506,7 @@ - (void)layoutSubviews }else{ targetIndex = 0; } - [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self scrollToItemAtIndex:targetIndex animated:NO]; } CGSize size = CGSizeZero; @@ -561,7 +569,7 @@ - (void)adjustWhenControllerViewWillAppera { long targetIndex = [self currentIndex]; if (targetIndex < _totalItemsCount) { - [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:targetIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO]; + [self scrollToItemAtIndex:targetIndex animated:NO]; } } diff --git a/SDCycleScrollView/ViewController.m b/SDCycleScrollView/ViewController.m index 53303212..063cb64a 100644 --- a/SDCycleScrollView/ViewController.m +++ b/SDCycleScrollView/ViewController.m @@ -101,7 +101,9 @@ - (void)viewDidLoad { // >>>>>>>>>>>>>>>>>>>>>>>>> demo轮播图2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // 网络加载 --- 创建带标题的图片轮播器 - SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 280, w, 180) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]]; + CGFloat width = 22.08; //在ipX上当滑动的轮播的View的宽度为小数时,轮播错误,会出现播放前两个,后面不播的情况 +// CGFloat width = 22; //当轮播的view宽度为整数的时候,正常播放 + SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(width, 280, w-width*2, 180) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]]; cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight; cycleScrollView2.titlesGroup = titles; From c2a37a96bb2c134828df04421f36a6e44b56c579 Mon Sep 17 00:00:00 2001 From: houhui <403262655@qq.com> Date: Wed, 2 Dec 2020 09:07:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AB=96=E7=9B=B4?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E6=83=85=E5=86=B5=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lib/SDCycleScrollView/SDCycleScrollView.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m index 664d55cd..1c143e48 100644 --- a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m +++ b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m @@ -156,7 +156,12 @@ - (void)scrollToItemAtIndex:(NSInteger)index animated:(BOOL)animated { // [_mainView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:YES]; //下面方法这样避免了轮播view宽度为小数的时候轮播错乱的情况 - [_mainView setContentOffset:CGPointMake(index*_flowLayout.itemSize.width, 0) animated:animated]; + if (_flowLayout.scrollDirection == UICollectionViewScrollDirectionHorizontal) { + [_mainView setContentOffset:CGPointMake(index*_flowLayout.itemSize.width, 0) animated:animated]; + }else{ + [_mainView setContentOffset:CGPointMake(0, index*_flowLayout.itemSize.width) animated:animated]; + } + } #pragma mark - properties