当用户滚动 uitableview 时,有什么办法可以知道当到达顶部时,许多 uitableviewcells 之一何时离屏 70%?我应该为此使用 willdisplaycell 吗?任何帮助表示赞赏。
1 回答
1
实施scrollViewDidScroll...
- 获取要跟踪的行/单元格的框架
- 将其与滚动偏移量进行比较以查看有多少可见
在这个简单的例子中,rowToTrackis an NSInteger,例如2第三行,sectionToTrackis an NSInteger,例如0第一节:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// index path for row we want to track
NSIndexPath *p = [NSIndexPath indexPathForRow:rowToTrack inSection:sectionToTrack];
// get frame for that row
CGRect r = [self.tableView rectForRowAtIndexPath:p];
// get bottom of row frame
CGFloat t1 = CGRectGetMaxY(r);
// get scroll content offset
CGFloat t2 = scrollView.contentOffset.y + scrollView.adjustedContentInset.top;
// height of visible portion of row frame
CGFloat visibleHeight = t1 - t2;
// as a percentage between 0 and 1
CGFloat pct = MAX(0.0, MIN(1.0, visibleHeight / r.size.height));
NSLog(@"Row %ld is %0.2f percent visible", rowToTrack, pct * 100);
}
于 2021-11-10T13:40:45.133 回答