我在 scrollViewDidScroll
上放置了一个滚动事件。
但是当用户滚动时,
它在使用 setContentOffSet
时也有效。
我想让它仅在用户滚动时起作用。
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (self.lastContentOffset > scrollView.contentOffset.y) {
let contentSize = scrollView.contentSize.height
let tableSize = scrollView.frame.size.height - scrollView.contentInset.top - scrollView.contentInset.bottom
let canLoadFromBottom = contentSize > tableSize
// Offset
let currentOffset = scrollView.contentOffset.y
let maximumOffset = scrollView.contentSize.height - scrollView.frame.size.height
let difference = maximumOffset - currentOffset
if canLoadFromBottom, difference <= -85.0{
loadMore()
}
self.lastContentOffset = scrollView.contentOffset.y
}
最佳答案
如果您在代码中滚动,之后您会立即收到一次委托(delegate)方法,因此很容易在代码滚动之前引发 Bool 标志并在委托(delegate)方法中检测到这一点。
关于ios - 可以区分用户滚动和编程滚动吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55699921/