Come posso aspettare che un'animazione finisca prima che inizi il prossimo in Swift? Ho fatto casino con if animation.animationDidStop... {}
, ma non funzionerà.Come posso terminare un'animazione prima che inizi il prossimo in Swift?
Ecco alcuni del mio codice finora:
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()
}
Utilizzando classe 'func animateWithDuration (_ durata: NSTimeInterval, animazioni animazioni:() -> Void, il completamento esecuzione:? ((Bool) -> Void))' e chiamando la seconda animazione sul completamento ? – Larme
e in che modo esattamente dovrei implementarlo nel mio codice? :) – user3157462
Mi spiace, ho letto male, stai usando animationImages. Ti suggerisco di utilizzare l'equivalente in Swift: http://stackoverflow.com/questions/9283270/access-method-after-uiimageview-animation-finish – Larme