diff --git a/SDCycleScrollView.xcodeproj/project.xcworkspace/xcuserdata/gsd.xcuserdatad/UserInterfaceState.xcuserstate b/SDCycleScrollView.xcodeproj/project.xcworkspace/xcuserdata/gsd.xcuserdatad/UserInterfaceState.xcuserstate index f17892ad..fc9ba951 100644 Binary files a/SDCycleScrollView.xcodeproj/project.xcworkspace/xcuserdata/gsd.xcuserdatad/UserInterfaceState.xcuserstate and b/SDCycleScrollView.xcodeproj/project.xcworkspace/xcuserdata/gsd.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h index 84f576bf..69eaa160 100644 --- a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h +++ b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h @@ -46,8 +46,12 @@ typedef enum { @protocol SDCycleScrollViewDelegate +/** 点击图片回调 */ - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index; +/** 图片滚动回调 */ +- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index; + @end @interface SDCycleScrollView : UIView diff --git a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m index 67ad75e3..033a2a01 100644 --- a/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m +++ b/SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m @@ -512,5 +512,16 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL } } +- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView +{ + int itemIndex = (scrollView.contentOffset.x + self.mainView.sd_width * 0.5) / self.mainView.sd_width; + if (!self.imagesGroup.count) return; // 解决清除timer时偶尔会出现的问题 + int indexOnPageControl = itemIndex % self.imagesGroup.count; + + if ([self.delegate respondsToSelector:@selector(cycleScrollView:didScrollToIndex:)]) { + [self.delegate cycleScrollView:self didScrollToIndex:indexOnPageControl]; + } +} + @end diff --git a/SDCycleScrollView/ViewController.m b/SDCycleScrollView/ViewController.m index 27ea13a5..7e32674b 100644 --- a/SDCycleScrollView/ViewController.m +++ b/SDCycleScrollView/ViewController.m @@ -90,7 +90,6 @@ - (void)viewDidLoad { cycleScrollView2.titlesGroup = titles; cycleScrollView2.currentPageDotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色 [self.view addSubview:cycleScrollView2]; - cycleScrollView2.infiniteLoop = NO; // --- 模拟加载延迟 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ @@ -117,4 +116,15 @@ - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtInde [self.navigationController pushViewController:[NSClassFromString(@"DemoVCWithXib") new] animated:YES]; } + +/* + +// 滚动到第几张图回调 +- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index +{ + NSLog(@">>>>>> 滚动到第%ld张图", (long)index); +} + + */ + @end