1

How rotate .transitionCurlDown animation to get the rotation of the book sheet (horizontal, not vertical), same as this:

enter image description here

There is vertical page curl animation:

UIView.transition(with: self.myView, duration: 0.7, 
options: .transitionCurlDown, animations: {
})

Important: I don't want to use transition between UIViewControllers or UIPageControllers, I want to apply animation on UIView on the current screen.

Ivan Kramarchuk
  • 226
  • 6
  • 17

2 Answers2

3

Solution:

func animatePage(side: PageCurl, textView: UITextView) {
    UIView.animate(withDuration: 0.3, animations: {
        let animation = CATransition()
        animation.duration = 0.3
        animation.startProgress = 0.0
        animation.endProgress = 1
        animation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
        animation.type = CATransitionType(rawValue: "pageCurl")
        if side == .left {
            animation.subtype = CATransitionSubtype(rawValue: "fromLeft")
        } else {
            animation.subtype = CATransitionSubtype(rawValue: "fromRight")
        }
        animation.isRemovedOnCompletion = false
        animation.isRemovedOnCompletion = false
        textView.layer.add(animation, forKey: "pageFlipAnimation")
    })
}

Use:

animatePage(side: .left, textView: myTextView)
Ivan Kramarchuk
  • 226
  • 6
  • 17
1

Just one note to the accepted answer. If you want to use it like book flip animation, change your imageView.image from cover to page, for example, before this line animatePage(side: .left, textView: myTextView)

So if you have cover image and page image, your code should be like:

imageView.image = UIImage(named: "page.png")
animatePage(side: .right, view: imageView)

And it will give your a nice looking flip animation from cover to page

nastassia
  • 807
  • 1
  • 12
  • 31