How do I wait for one animation to finish before the next one starts in Swift? I have been messing around with if animation.animationDidStop... {}
, but it won't work.
Here's some of my code so far:
class ViewController: UIViewController {
@IBOutlet weak var purpleRing: UIImageView!
@IBOutlet weak var beforeCountdownAnimation: UIImageView!
var imageArray = [UIImage]()
var imageArray2 = [UIImage]()
override func viewDidLoad() {
super.viewDidLoad()
for e in -17...0 {
let imageName2 = "\(e)"
imageArray2.append(UIImage(named: imageName2)!)
}
for t in 1...97 {
let imageName = "\(t)"
imageArray.append(UIImage(named: imageName)!)
}
}
func startAnimation() -> Void {
purpleRing.animationImages = imageArray
purpleRing.animationDuration = 5.0
purpleRing.startAnimating()
}
func startAnimation2() -> Void {
beforeCountdownAnimation.animationImages = imageArray2
beforeCountdownAnimation.animationDuration = 1.0
beforeCountdownAnimation.startAnimating()
}
@IBAction func startAnimations(sender: AnyObject) {
startAnimation()
startAnimation2()
}
class func animateWithDuration(_ duration: NSTimeInterval, animations animations: () -> Void, completion completion: ((Bool) -> Void)?)
and calling the second animation on the completion? – Electrolysis