image.png
UITableView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat y = scrollView.contentOffset.y;
for (NSInteger i = 0; i < self.models.count; i ++) {
if (self.tableView.numberOfSections > i) {
CGFloat offset = [self.tableView rectForSection:i].origin.y;
CGFloat height = [self.tableView rectForSection:i].size.height;
if (y >= offset && y <= offset + height) {
// 滚动到第 i 组
}
}
}
}
UICollectionView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSIndexPath *currentIndexPath = [self.goodsList indexPathForItemAtPoint:scrollView.contentOffset];
if (currentIndexPath != nil) {
// currentIndexPath.section
}
}