Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to flash an UIImageview on the iPad, how do I do that?

I want to let a UIImageView flash several times.

Currently I don't know how to do that.

Actual code:

-(void)arrowsAnimate{
    [UIView animateWithDuration:1.0 animations:^{
        arrow1.alpha = 1.0;
        arrow2.alpha = 1.0;
        arrow3.alpha = 1.0;
        NSLog(@"alpha 1");
    } completion:^(BOOL finished){        

        [self arrowsAnimate2];
                    
    }];
}

-(void)arrowsAnimate2{
    [UIView animateWithDuration:1.0 animations:^{
         arrow1.alpha = 0.0;
         arrow2.alpha = 0.0;
         arrow3.alpha = 0.0;
         NSLog(@"alpha 0");
    } completion:^(BOOL finished){;}];
}

later on I call it like this:

for (int i = 0;i < 10; i++){
[self arrowsAnimate]; }

This gives me 10x alpha 1, and then 10x alpha 0. In the middle we see only one animation. Any suggestions?

Thanks.

like image 938
FreXxX Avatar asked Feb 18 '11 16:02

FreXxX


1 Answers

There is a simpler way to achieve a flashing animation using only 1 animation block:

aview.alpha = 1.0f;
[UIView animateWithDuration:0.5f
                      delay:0.0f 
                    options:UIViewAnimationOptionAutoreverse
                 animations:^ {
       [UIView setAnimationRepeatCount:10.0f/2.0f];
       aview.alpha = 0.0f;
} completion:^(BOOL finished) { 
       [aview removeFromSuperview]; 
}];    

The trick is to use [UIView setAnimationRepeatCount:NTIMES/2]; *_inside_* your animation block. No need for extra functions or extra loops.

like image 74
Dado Avatar answered Oct 13 '22 00:10

Dado