如何旋转.transitionCurlDown动画?

时间:2018-10-18 04:17:55

标签: ios swift animation

如何旋转.transitionCurlDown动画以获取书页的旋转(水平而非垂直),与此相同:

enter image description here

有垂直页面卷曲动画:

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

重要:我不想在UIViewControllers或UIPageControllers之间使用过渡,我想在当前屏幕上的UIView上应用动画。

2 个答案:

答案 0 :(得分:1)

只需一个音符就可以接受答案。如果您想像翻书动画那样使用它,请将imageView.image从封面更改为页面,例如,在此行animatePage(side: .left, textView: myTextView)

之前

因此,如果您有cover张图片和page张图片,则您的代码应类似于:

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

这将为您提供从封面到页面的漂亮翻页动画

答案 1 :(得分:0)

解决方案:

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")
    })
}

使用:

animatePage(side: .left, textView: myTextView)
相关问题