【发布时间】:2021-12-22 15:21:52
【问题描述】:
当用户滚动 uitableview 时,有什么方法可以知道到达顶部时,许多 uitableviewcell 之一何时离屏 70%?我应该为此使用 willdisplaycell 吗?任何帮助表示赞赏。
【问题讨论】:
标签: ios objective-c
当用户滚动 uitableview 时,有什么方法可以知道到达顶部时,许多 uitableviewcell 之一何时离屏 70%?我应该为此使用 willdisplaycell 吗?任何帮助表示赞赏。
【问题讨论】:
标签: ios objective-c
实现scrollViewDidScroll...
在这个简单的例子中,rowToTrack 是一个NSInteger,例如第三行的2,sectionToTrack 是一个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);
}
【讨论】: