我在寻找一种方法来指示一个与触摸(Began/Moved/Ended)交互的
UIView
页面翻页动画,就像这个视频展示的那样。
注意:
- 我不能使用UIPageController。动画应该应用于
UIView
。 - 动画和触摸开始、触摸移动和触摸结束之间的交互非常重要。完全像视频中展现的那样。
示例代码,但无法与触摸交互:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
BackBtn.layer.cornerRadius = 5.0
AnimationBtn.layer.cornerRadius = 5.0
transition.delegate = self
transition.duration = 1.5
transition.startProgress = 0
transition.endProgress = 1
transition.type = CATransitionType(string: "pageCurl") as String
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.fillMode = kCAFillModeBoth
transition.isRemovedOnCompletion = false
}
在接触中移动:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
if let touch = touches.first {
let endPosition = touch.location(in: touch.view)
differenceX = startPosition.x - endPosition.x
differenceY = endPosition.y - startPosition.y
transition.subtype = kCATransitionFromRight
touch.view!.layer.add(transition, forKey: kCATransition)
webView.scrollView.contentOffset = CGPoint(x: nextPage + differenceX, y: 0)
}
}