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];
}
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.
精彩评论