I have 8 UImageView
s that I am adding animations to. I know I can make the animation eight times, but can I use a loop -and maybe interpolation- for it?
Here is my code for the animation:
override func viewDidLoad() {
super.viewDidLoad()
self.dieImage0.animationImages = [
UIImage(named: "dicey-die1")!,
UIImage(named: "dicey-die2")!,
UIImage(named: "dicey-die3")!,
UIImage(named: "dicey-die4")!,
UIImage(named: "dicey-die5")!,
UIImage(named: "dicey-die6")!,
UIImage(named: "dicey-die1")!,
UIImage(named: "dicey-die2")!,
UIImage(named: "dicey-die3")!,
UIImage(named: "dicey-die4")!,
UIImage(named: "dicey-die5")!,
UIImage(named: "dicey-die6")!,
UIImage(named: "dicey-die1")!,
UIImage(named: "dicey-die2")!,
UIImage(named: "dicey-die3")!,
UIImage(named: "dicey-die4")!,
UIImage(named: "dicey-die5")!,
UIImage(named: "dicey-die6")!,
UIImage(named: "dicey-die1")!,
UIImage(named: "dicey-die2")!,
UIImage(named: "dicey-die3")!,
UIImage(named: "dicey-die4")!,
UIImage(named: "dicey-die5")!,
UIImage(named: "dicey-die6")!
]
self.dieImage0.animationRepeatCount = 1
self.dieImage0.animationDuration = 1.0
}
And for starting the animation:
override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent) {
self.dieImage0.startAnimating() /* <======== */
dieImage0.image = randomImages.randomDice();
dieImage1.image = randomImages.randomDice();
dieImage2.image = randomImages.randomDice();
dieImage3.image = randomImages.randomDice();
dieImage4.image = randomImages.randomDice();
dieImage5.image = randomImages.randomDice();
dieImage6.image = randomImages.randomDice();
dieImage7.image = randomImages.randomDice();
println("Motion Ended")
}
I want to animate each dieImage
Edit
I have several UIImageView
s with @IBOutlet
s that I want to animate.
@IBOutlet weak var dieImage0: UIImageView!
@IBOutlet weak var dieImage1: UIImageView!
@IBOutlet weak var dieImage2: UIImageView!
@IBOutlet weak var dieImage3: UIImageView!
@IBOutlet weak var dieImage4: UIImageView!
@IBOutlet weak var dieImage5: UIImageView!
@IBOutlet weak var dieImage6: UIImageView!
@IBOutlet weak var dieImage7: UIImageView!
How do I loop through them instead of making a separate animation for each, I already have one animation setup; see above.
Update:
Everything is working as wanted except two dice have rebelled. The first one (dieImage0
) consistently lands on a 1, the second one (dieImage5
) won't do anything at all!
Update 2:
This is the code I used for my animation:
let dieImages = [dieImage0, dieImage1, dieImage2, dieImage3, dieImage4, dieImage5, dieImage6, dieImage7]
for die in dieImages {
die.animationImages = [
UIImage(named: "dicey-die2")!,
UIImage(named: "dicey-die6")!,
UIImage(named: "dicey-die1")!,
UIImage(named: "dicey-die4")!,
UIImage(named: "dicey-die3")!,
UIImage(named: "dicey-die5")!,
UIImage(named: "dicey-die3")!,
UIImage(named: "dicey-die1")!,
UIImage(named: "dicey-die6")!,
UIImage(named: "dicey-die3")!,
UIImage(named: "dicey-die5")!,
UIImage(named: "dicey-die2")!,
UIImage(named: "dicey-die4")!
]
die.animationRepeatCount = 1
die.animationDuration = 1.0
}
Everything works now!