Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift animation numbers of repeat

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


    })

}
like image 804
Clarence Avatar asked Dec 15 '22 05:12

Clarence


1 Answers

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


})
like image 155
NightFury Avatar answered Dec 23 '22 03:12

NightFury