iphone - 如何获得 UITableView 的可见矩形?

标签 iphone objective-c cocoa-touch uitableview uiscrollview

我正在尝试检测用户是否已滚动到 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/

相关文章:

ios - Swift 中的 NSTextStorage 子类不更新 UITextView

cocoa-touch - 在 iOS 中淡入异步加载的图像

html - iPhone 不会尊重大于 ~1000 的元视口(viewport)。任何超过 1000 的值都被视为 ~1000! :(

iphone - 根据选定的标签栏项目更改导航项标题的标题

iOS - 空白出现在 iPhone 6 和 6+

ios - 使用 AVCaptureDevice 扫描图像后立即继续

iOS 8 : How to implement a rotating view controller on top of a portrait-only app?

iphone - 检测 2 个 subview 的触摸

iOS - 如何在 xcode 中解析 Json 数组并将结果保存为字符串

iphone - 如何在 Xcode 中知道我的对象图占用了多少内存?