Skip to content

Commit

Permalink
添加图片contentmode接口,block监听点击接口,滚动到某张图片监听
Browse files Browse the repository at this point in the history
  • Loading branch information
gsdios committed Dec 31, 2015
1 parent 798ea77 commit e462019
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
Binary file not shown.
4 changes: 4 additions & 0 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ typedef enum {

@protocol SDCycleScrollViewDelegate <NSObject>

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index;

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index;

@end

@interface SDCycleScrollView : UIView
Expand Down
11 changes: 11 additions & 0 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion SDCycleScrollView/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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(), ^{
Expand All @@ -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

0 comments on commit e462019

Please sign in to comment.