ios - 检测 UITableView 何时滚动到底部

标签 ios swift uitableview

下面的帖子是否仍然是检测 UITableView 实例何时滚动到底部 [在 Swift 中] 或它是否已被更改(如:改进)的公认方法?

Problem detecting if UITableView has scrolled to the bottom

谢谢。

最佳答案

试试这个:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    let height = scrollView.frame.size.height
    let contentYOffset = scrollView.contentOffset.y
    let distanceFromBottom = scrollView.contentSize.height - contentYOffset

    if distanceFromBottom < height {
        print("You reached end of the table")
    }
}

或者你可以这样试试:

if tableView.contentOffset.y >= (tableView.contentSize.height - tableView.frame.size.height) {    
    /// you reached the end of the table
}

关于ios - 检测 UITableView 何时滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39015228/

相关文章:

ios - AVPlayer不播放Video,播放Button带Line through

ios - 检查 UIImageView 中的图像不是占位符图像并附加到 UIImage 数组

objective-c - 从 objective-C 桥接到 swift 时,swift 编译器如何识别变量是副本还是强变量?

ios - 无法使用参数列表类型调用 'sendData' '(Int32, toPeers : [AnyObject]! ,

iphone - UITableView 中的错误

ios - 在显示/隐藏键盘 iOS11 上滚动 UITableView

iphone - 如何强制我的 iPhone 应用程序保持特定方向

android - 移动设备上的按钮动态填充/高度问题

objective-c - 选择器/方法名称作为字符串参数

swift - 使 UIImage 适合 UIView 内部的 UIImageView