gsdios / SDCycleScrollView

Autoscroll Banner. 无限循环图片、文字轮播器。
MIT License
6.18k stars 1.5k forks source link

MISSAJJ修改bug //原因:在做IOS多屏幕适配时,算出的currentIndex会出错,会导致出现轮播几次就被停止了 #126

Open MISSAJJ opened 8 years ago

MISSAJJ commented 8 years ago
MISSAJJ commented 8 years ago

如果适配缩放比例获得最终控件W为 336.375000 CGfloat sliderW = 336.375000;

SDCycleScrollView *cycleScrollView = [cycleScrollViewWithFrame:CGRectMake(0,0,sliderW,sliderH) delegate:self placeholderImage: placeholderImage:placeholderImage];

请看打印数据:

轮播几次后,_mainView.contentOffset.x 就一直为 35319.333333, 导致无限轮播停止运行

2016-02-18 17:36:24.766 shtrip[1136:295048] _mainView.contentOffset.x33637.666667====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:26.766 shtrip[1136:295048] _mainView.contentOffset.x33974.000000====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:28.766 shtrip[1136:295048] _mainView.contentOffset.x34310.333333====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:30.766 shtrip[1136:295048] _mainView.contentOffset.x34646.666667====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:32.766 shtrip[1136:295048] _mainView.contentOffset.x34983.000000====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:34.766 shtrip[1136:295048] _mainView.contentOffset.x35319.333333====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:36.766 shtrip[1136:295048] _mainView.contentOffset.x35319.333333====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:38.766 shtrip[1136:295048] _mainView.contentOffset.x35319.333333====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:40.766 shtrip[1136:295048] _mainView.contentOffset.x35319.333333====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:42.766 shtrip[1136:295048] _mainView.contentOffset.x35319.333333====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:44.766 shtrip[1136:295048] _mainView.contentOffset.x35319.333333====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:46.766 shtrip[1136:295048] _mainView.contentOffset.x35319.333333====_flowLayout.itemSize.width336.375000 2016-02-18 17:36:48.766 shtrip[1136:295048] _mainView.contentOffset.x35319.333333====_flowLayout.itemSize.width336.375000

所以先强转为int再算出的int currentIndex就不会错了 int currentIndex = (int)_mainView.contentOffset.x / (int)_flowLayout.itemSize.width;