首页 > 解决方案 > Swift4 中所有视图控制器的连续背景动画

问题描述

我的第一个视图控制器上有一个无限旋转的图像作为背景,效果很好!

 @IBOutlet var background: UIImageView!

func rotate1(imageView: UIImageView, aCircleTime: Double) {

    let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation")
    rotationAnimation.fromValue = 0.0
    rotationAnimation.toValue = -Double.pi * 2
    rotationAnimation.speed = 0.1
    rotationAnimation.duration = aCircleTime
    rotationAnimation.repeatCount = .infinity
    imageView.layer.add(rotationAnimation, forKey: nil)
}

override func viewWillAppear(_ animated: Bool) {
    rotate1(imageView: background, aCircleTime: Double.pi)
    background.transform = background.transform.rotated(by: CGFloat(Double.pi))
}

(来源:https ://github.com/vin20777/infinite-rotate-animation )

当用户在应用程序的各种视图控制器中移动时,是否可以让这种旋转在后台继续可见且不间断?如果是这样,它是如何完成的?

感谢您的任何帮助!

这是背景动画的 gif。

标签: xcodeswift4

解决方案


推荐阅读