I'm looking for a way to indicate a page curl animation on an UIView that interactive with touch(Began/Moved/Ended) like this
Note:
- I can't use UIPageController. The animation should be applied to the
UIView. - The interaction between the animation and the start of the touch, touch movement and touch end is very important. Exactly like video
Sample Code but dont work with touch:
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
}
in touch moved:
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)
}
}
I found answer. I just need to change the
transition.startProgressandtransition.endProgress.Sample code: