tags:

views:

28

answers:

1

I have two animation methods, basically the just repeat... How do I prevent them from overlapping and flickering, is there a convenient way to do this?

Thanks,

-(void) doPowerChangeAnimUp
{
    powerIconChange .alpha    = 0;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:)];
    [UIView setAnimationDelegate:self] ;
    [UIView setAnimationDuration:2];
    [powerIconChange  setAlpha:1];
    [UIView commitAnimations];
}

-(void)animationDidStop:(NSString *)animationID 
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelegate:self] ;
    [UIView setAnimationDidStopSelector:@selector(doPowerChangeAnimUp)];
    [UIView setAnimationDuration:2];
    [powerIconChange  setAlpha:0];
    [UIView commitAnimations];
}
A: 

You can try setting the animation to autoreverse instead of creating a new animation, that may generate a smoother "bounce":

-(void) doPowerChangeAnimUp
{
    powerIconChange .alpha    = 0;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationRepeatAutoreverses:YES];
    [UIView setAnimationRepeatCount:2];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:)];
    [UIView setAnimationDelegate:self] ;
    [UIView setAnimationDuration:2];
    [powerIconChange  setAlpha:1];
    [UIView commitAnimations];
}

Even more, instead of calling the did stop selector, you may increase the animationRepeatCount to a higher value, so that it covers all your animation with a single beginAnimations block.

pgb
OK, but how do I not re-create an animation instance, it's playing already, is there a BOOL to tell me so?
ReduxDJ