gpt4 book ai didi

ios - UIScrollView contentOffset 的一个错误?

转载 作者:搜寻专家 更新时间:2023-10-31 22:42:58 26 4
gpt4 key购买 nike

我将 scrollView 的属性 isPagingEnabled 设置为 true,如下所示:

let scrollView = UIScrollView(frame: view.bounds)
scrollView.contentSize = CGSize(width: view.bounds.width * 2, height: 0)
scrollView.delegate = self
scrollView.isPagingEnabled = true
view.addSubview(scrollView)

和委托(delegate)方法:

func scrollViewDidScroll(_ scrollView: UIScrollView) {
print(scrollView.contentOffset.x)
}

当 ScrollView 到边界时,控制台打印,如图:

enter image description here

enter image description here

红框里的值应该不会打印出来吧?

但是,如果将isPagingEnabled设置为false,控制台打印是正常的。这是 UIScrollView 的错误吗?

最佳答案

您的内容偏移量显示错误,因为您在 viewdidload 中使用内容大小在此方法中使用内容大小而不是打印您的内容偏移量

 override func viewDidLayoutSubviews()
{
scrollView.contentSize = CGSize(width: view.bounds.width * 2, height: 0)
}

关于ios - UIScrollView contentOffset 的一个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43316178/

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