我有一个滚动视图,其中三个屏幕填充图像彼此相邻。 为了给人一种圆形滚动的错觉,我实现了这一点:
class BoardContainerViewController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var board1: UIView!
@IBOutlet weak var board2: UIView!
@IBOutlet weak var board3: UIView!
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
scrollView.contentSize = CGSize(width: UIScreen.main.bounds.width*3, height: UIScreen.main.bounds.height)
scrollView.setContentOffset(CGPoint(x: UIScreen.main.bounds.width, y: 0), animated: false)
scrollView.delegate = self
// Do any additional setup after loading the view.
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if(scrollView.contentOffset.x < UIScreen.main.bounds.width / 2) {
scrollView.setContentOffset(CGPoint(x: scrollView.contentOffset.x + UIScreen.main.bounds.width, y: 0), animated: false)
}
if(scrollView.contentOffset.x > UIScreen.main.bounds.width * 1.5) {
scrollView.setContentOffset(CGPoint(x: scrollView.contentOffset.x - UIScreen.main.bounds.width, y: 0), animated: false)
}
}
func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) {
scrollView.setContentOffset(scrollView.contentOffset,animated: false)
}
}
它工作正常,但是当它在减速期间被触发时,减速将中止。我能以某种方式恢复它吗?