Reputation: 1943
I have the following code want to fade in and out a UILabel. But I just want it to repeat the fade in and out 5 times. My question is how to set the animation only repeat 3 times?
func savingIcon(){
Loading.hidden=false
UIView.animateWithDuration(1.0,
delay: 0.0,
options: [ .CurveEaseInOut],
animations: {
self.Loading.alpha=0.0;
self.Loading.alpha=1.0;
self.Loading.alpha=0.0;
self.Loading.alpha=1.0;
self.Loading.alpha=0.0;
},
completion: { finished in
print("Save done")
self.Loading.hidden=true
})
}
Upvotes: 4
Views: 4617
Reputation: 13546
If you want to repeat your animation block 5 times, try doing:
UIView.animateWithDuration(1.0,
delay: 0.5,
options: [ .CurveEaseInOut, .Repeat],
animations: {
UIView.setAnimationRepeatCount(5)
self.Loading.alpha=0.0;
self.Loading.alpha=1.0;
self.Loading.alpha=0.0;
self.Loading.alpha=1.0;
self.Loading.alpha=0.0;
},
completion: { finished in
print("Save done")
self.Loading.hidden=true
})
Upvotes: 12