iOS swift : scrollview does not call didscrolltotop

标签 ios swift uiscrollview

晚上:我有一个 ScrollView ,里面有 3 个 View ..

我对 ScrollView 委托(delegate)有疑问。

didscrolltotop 永远不会被调用,而 did 滚动是...

我不明白原因...

有什么帮助吗?

enter image description here

最佳答案

看起来它只在某些情况下被调用,documentation讨论 scroll-to-top gesture 意味着它可能仅在 轻按状态栏 后起作用,而不是基本滚动。似乎还需要将 scrollsToTop 属性设置为 true

The scroll view sends this message when it finishes scrolling to the top of the content. It might call it immediately if the top of the content is already shown. For the scroll-to-top gesture (a tap on the status bar) to be effective, the scrollsToTop property of the UIScrollView must be set to YES.

您还可以使用 contentOffset

简单地检测内容的顶部
func scrollViewDidScroll(_ scrollView: UIScrollView) {
    print("The current Y offset is \(scrollView.contentOffset.y)")
    if scrollView.contentOffset.y == 0 {
        print("we are at the top")
    }
}

您可能还想考虑使用 scrollViewDidEndDecelerating方法,因为这意味着您只会在 ScrollView 稳定下来后收到一个事件。

关于iOS swift : scrollview does not call didscrolltotop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46793858/

相关文章:

ios - 如何正确生成时间戳

ios - 从 imageview 点击手势获取索引或标签值

iphone - 如何在 UIScrollView 中找到 UIImageView 的缩放因子

ios - 如何将用户名和电子邮件保存到 firebase

Swift 4.2 - 类型附近的 __shared 属性

ios - 如何在 Objective C 的 UIScrollView 中禁用动画滚动?

ios - UILabel作为tableViewCell的accessoryView向上移动

ios - 升级到 MT 4.0 后索引 TableViews 不显示

java - Apple APNS - 每秒应从服务器发送多少推送

xcode - 在现代 Swift OSX 应用程序中组织 XIB 和 Storyboard