0

I've got an infinitely rotating image as the background on my first view controller and it works so good!

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

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

Is it possible to have this rotation continue visible and uninterrupted in the background as the user moves through the various view controllers of the app? If so, how is it done?

Thank you for any help!

Here's a gif of the background animation.

Derence
  • 408
  • 5
  • 18
  • Create a base view controller with the animation and present all the other controllers modally over it. Also, you should set a transparent background to them to see the animation. More information about this: https://stackoverflow.com/q/27669699/3151675 – Tamás Sengel Oct 17 '18 at 00:05
  • 1
    Thanks @TamásSengel, that worked perfectly. I just added in the other view controllers and the rotating animation in the first controller stayed visible. override func viewDidLoad() { super.viewDidLoad() view.isOpaque = false view.backgroundColor = .clear // try other colors, say: .white or black with Alpha etc. } Thanks so much! – Derence Oct 18 '18 at 14:56

0 Answers0