我正在尝试检测用户是否已滚动到 UITableView 的底部,以便我可以做一些额外的事情。为了正确计算,我需要获取 UITableView 的可见矩形。我怎样才能做到这一点?
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
int currentMaxPosition = CGRectGetMaxY([self.tableView visibleRect]);
int currentMinPosition = CGRectGetMinY([self.tableView visibleRect]);
int tableViewBottom = [self.tableView bounds].size.height - 100;
int tableViewTop = 0;
//get older messages once we're near the bottom
if (currentMaxPosition > tableViewBottom - 100)
{
NSLog(@"WE AT THE BOTTOM!");
}
}
最佳答案
UITableView 只是 UIScrollView 的子类,所以所有常用的 UIScrollView 方法都适用,例如UITableView 的可见矩形就是它的边界:
CGRect visibleRect = [myTableView bounds];
visibleRect 的起源只是 contentOffset,因此您可以使用的另一种方法是:
CGFloat distanceFromBottom = [self.tableView contentSize].height - [self.tableView contentOffset].y;
关于iphone - 如何获得 UITableView 的可见矩形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6777570/