Swift4中所有视图控制器的连续背景动画

时间:2018-10-16 23:36:34

标签: xcode 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

当用户在应用程序的各个视图控制器中移动时,是否有可能使旋转继续在后台可见并且在后台不间断?如果是这样,怎么做?

谢谢您的帮助!

Here's a gif of the background animation.

0 个答案:

没有答案