如何解决触摸手势在自动滚动iOS上不起作用
我正在尝试实现自动滚动。我完成了自动滚动部分,但现在触摸手势无法正常工作。触摸手势包括用户交互,以向左和向右滚动,并在点按任何项目时转到详细信息控制器等。
这是我的代码
var sponsorScroll: UIScrollView!
var xOffSet: CGFloat = 0
override func viewDidAppear(_ animated: Bool) {
let timer = Timer.scheduledTimer(timeInterval: 1,target: self,selector: #selector(timerAction),userInfo: nil,repeats: true)
RunLoop.main.add(timer,forMode: RunLoop.Mode.common)
}
@objc func timerAction() {
print(1)
self.xOffSet += 50;
DispatchQueue.main.async {
print(2)
if self.sponsorScroll.contentSize.width < (self.sponsorScroll.contentOffset.x + UIScreen.main.bounds.width) {
self.xOffSet = 0
UIView.animate(withDuration: 1,delay: 0,options: UIView.AnimationOptions.curveLinear,animations: {
print(4)
self.sponsorScroll.contentOffset.x = self.xOffSet
},completion: nil)
}
else {
UIView.animate(withDuration: 1,animations: {
print(3)
self.sponsorScroll.contentOffset.x = self.xOffSet
},completion: nil)
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。