开发者

How to control overlapping Alpha fades on iPhone

开发者 https://www.devze.com 2023-01-03 19:21 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消