Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView blinking animation

I am trying to make a UIImageView blink upon viewDidLoad. I am not sure what the best way to do this is. I've tried using loops with .hidden=YES and .hidden=NO but this seems like a bad way to do this. I need some proper advice.

like image 214
Owen Avatar asked Dec 04 '22 02:12

Owen


1 Answers

try this :

-(void)blink:(UIView*)view count:(int) count
{
    if(count == 0)
    {
        return;
    }

    [UIView animateWithDuration:0.2 animations:^{

        view.alpha = 0.0;

    } completion:^(BOOL finished){

        [UIView animateWithDuration:0.2 animations:^{

            view.alpha = 1.0;

        } completion:^(BOOL finished){

            [self blink:view count:count-1];

        }];


    }];
}

or if you want it to blink forever try this :

-(void)blinkForever:(UIView*)view
{
    [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat animations:^{

        view.alpha = 0.0;

    } completion:nil];
}
like image 123
m.eldehairy Avatar answered Dec 20 '22 16:12

m.eldehairy