gpt4 book ai didi

ios - 如何在不中断其他功能的情况下使用动画滚动 UIScrollView?

转载 作者:行者123 更新时间:2023-11-28 05:59:21 25 4
gpt4 key购买 nike

在此应用程序中,您可以点击经文以突出显示它们。我添加了滚动功能,以便它使用 animate 自行滚动。但是每当滚动开始时,在我停止滚动之前我无法再点击这些经文。到目前为止,这是我的代码:

@objc func move_view() {
print("moved view")
self.current_scroll_position += 3
UIView.animate(withDuration: 0.5, delay: 0, options: .curveLinear, animations: {
self.scroll_view.contentOffset = CGPoint(x: 0, y: CGFloat(self.current_scroll_position))
}, completion: nil)
}

// start scrolling
print("start scrolling")
self.current_scroll_position = Int(self.scroll_view.contentOffset.y)

self.scroll_timer = Timer.scheduledTimer(timeInterval: TimeInterval(0.5), target: self, selector: #selector(self.move_view), userInfo: nil, repeats: true)
RunLoop.current.add(self.scroll_timer, forMode: .commonModes)

self.is_scrolling = true

这是没有滚动的突出显示:

without scroll

这是滚动的样子:

with scroll

如您所见,滚动时无法点击,我该如何解决?

最佳答案

UIViewAnimationOptions 有一个常量 allowUserInteraction,所以你可以这样使用它:

UIView.animate(withDuration: 0.5, delay: 0, options: [.curveLinear, .allowUserInteraction], animations: {
self.scroll_view.contentOffset = CGPoint(x: 0, y: CGFloat(self.current_scroll_position))
}, completion: nil)

当动画发生时,应该允许用户在 View 上做手势。

关于ios - 如何在不中断其他功能的情况下使用动画滚动 UIScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50296599/

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