如何在iPhone上控制重叠Alpha淡入淡出

时间:2010-06-15 21:12:48

标签: iphone uiview

我有两种动画方法,基本上只是重复...如何防止它们重叠和闪烁,有没有一种方便的方法呢?

谢谢,

-(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];
}

1 个答案:

答案 0 :(得分:0)

您可以尝试将动画设置为自动反转,而不是创建新动画,这可能会产生更平滑的“反弹”:

-(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];
}

更多的是,您可以将animationRepeatCount增加到更高的值,而不是调用停止选择器,这样它就可以用一个beginAnimations块覆盖所有动画。