gpt4 book ai didi

iOS swift : scrollview does not call didscrolltotop

转载 作者:搜寻专家 更新时间:2023-11-01 07:08:11 24 4
gpt4 key购买 nike

晚上:我有一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com