我有两种动画方法,基本上只是重复...如何防止它们重叠和闪烁,有没有一种方便的方法呢?
谢谢,
-(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];
}
答案 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
块覆盖所有动画。