Skip to content

Commit

Permalink
Merge pull request gsdios#433 from Kyoooooo/master
Browse files Browse the repository at this point in the history
增加通过Nib注册cell方法,增加一个可以手动控制滚动到哪一个index的方法
  • Loading branch information
gsdios authored Nov 26, 2017
2 parents 5667837 + ed38bd9 commit a07dab5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ typedef enum {
/** 如果你需要自定义cell样式,请在实现此代理方法返回你的自定义cell的class。 */
- (Class)customCollectionViewCellClassForCycleScrollView:(SDCycleScrollView *)view;

/** 如果你需要自定义cell样式,请在实现此代理方法返回你的自定义cell的Nib。 */
- (UINib *)customCollectionViewCellNibForCycleScrollView:(SDCycleScrollView *)view;

/** 如果你自定义了cell样式,请在实现此代理方法为你的cell填充数据以及其它一系列设置 */
- (void)setupCustomCell:(UICollectionViewCell *)cell forIndex:(NSInteger)index cycleScrollView:(SDCycleScrollView *)view;

Expand Down Expand Up @@ -202,4 +205,7 @@ typedef enum {
/** 清除图片缓存(兼容旧版本方法) */
- (void)clearCache;

/** 可以调用此方法手动控制滚动到哪一个index */
- (void)makeScrollViewScrollToIndex:(NSInteger)index;

@end
21 changes: 19 additions & 2 deletions SDCycleScrollView/Lib/SDCycleScrollView/SDCycleScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ - (void)setDelegate:(id<SDCycleScrollViewDelegate>)delegate

if ([self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] && [self.delegate customCollectionViewCellClassForCycleScrollView:self]) {
[self.mainView registerClass:[self.delegate customCollectionViewCellClassForCycleScrollView:self] forCellWithReuseIdentifier:ID];
}else if ([self.delegate respondsToSelector:@selector(customCollectionViewCellNibForCycleScrollView:)] && [self.delegate customCollectionViewCellNibForCycleScrollView:self]) {
[self.mainView registerNib:[self.delegate customCollectionViewCellNibForCycleScrollView:self] forCellWithReuseIdentifier:ID];
}
}

Expand Down Expand Up @@ -571,8 +573,11 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
long itemIndex = [self pageControlIndexWithCurrentCellIndex:indexPath.item];

if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] &&
[self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] &&
[self.delegate customCollectionViewCellClassForCycleScrollView:self]) {
[self.delegate respondsToSelector:@selector(customCollectionViewCellClassForCycleScrollView:)] && [self.delegate customCollectionViewCellClassForCycleScrollView:self]) {
[self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self];
return cell;
}else if ([self.delegate respondsToSelector:@selector(setupCustomCell:forIndex:cycleScrollView:)] &&
[self.delegate respondsToSelector:@selector(customCollectionViewCellNibForCycleScrollView:)] && [self.delegate customCollectionViewCellNibForCycleScrollView:self]) {
[self.delegate setupCustomCell:cell forIndex:itemIndex cycleScrollView:self];
return cell;
}
Expand Down Expand Up @@ -672,5 +677,17 @@ - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
}
}

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

[self scrollToIndex:(int)index];

if (self.autoScroll) {
[self setupTimer];
}
}

@end

0 comments on commit a07dab5

Please sign in to comment.