gpt4 book ai didi

ios - UIScrollView 应该只向下滚动

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

我有一个 ScrollView ,我希望该 ScrollView 只能向下滚动,而不能向任何其他方向滚动。这与水平或垂直无关,但我希望 ScrollView 在垂直模式下仅向下滚动而不是向上滚动。

最佳答案

解决方案

子类化 UIScrollView 并覆盖限制水平滚动的方法,并且仅在方向向下时滚动:

class DownwardsOnlyScrollView: UIScrollView
{
override func setContentOffset(_ contentOffset: CGPoint, animated: Bool) {
// restrict movement to vertical only
let newOffset = CGPoint(x: 0, y: contentOffset.y)

//only scroll if scroll direction is downwards
if newOffset.y > self.contentOffset.y
{
super.setContentOffset(newOffset, animated: animated)
}
}
}

关于ios - UIScrollView 应该只向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43932260/

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