我需要实时获取表格 View 的滚动位置。 我目前正在做的是:
func animationOffset() {
let offset = tableView.contentOffset.y
}
这个函数连接到一个定时器
timer = NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: #selector(TimelineViewController.animationOffset), userInfo: nil, repeats: true)
如果用户将手指从屏幕上移开,这段代码可以正常工作,但如果他们不这样做并继续滚动,偏移量将永远不会更新,我的应用程序将无法正常运行。
最佳答案
你可以实现
func scrollViewDidScroll(scrollView: UIScrollView)
UITableViewDelegate
,当 tableview 的滚动位置发生变化时调用,您可以使用 tableView.contentOffset.y
获取滚动位置。
关于ios - 如何实时获取UITableView的滚动位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36961360/