Iphone 简单动画的问题
我在按钮上使用动画,第一次单击显示视图,第二次单击隐藏视图。 这是我隐藏视图的代码Iphone 简单动画的问题,iphone,uianimation,Iphone,Uianimation,我在按钮上使用动画,第一次单击显示视图,第二次单击隐藏视图。 这是我隐藏视图的代码 -(IBAction)clickme { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationDelegate:self];
-(IBAction)clickme
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[view1 setAlpha:0.0];
[UIView commitAnimations];
}
类似的代码用于显示视图
但当用户反复点击按钮时,问题就出现了……这意味着我的动画使用了2秒钟,但如果用户在动画中按下相同的按钮,则输出结果非常糟糕
我不想在动画期间禁用该按钮
还有其他方法吗?您需要跟踪是否正在播放动画,如果正在播放,则忽略单击 声明一个实例变量
BOOL动画在类标题中选择code>,并在init
中将其初始化为NO
那么
您需要跟踪是否有动画正在进行,如果有,则忽略单击
声明一个实例变量BOOL动画在类标题中选择code>,并在init
中将其初始化为NO
那么
尝试使用+(void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState:
-(IBAction)clickme
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[view1 setAlpha:0.0];
[UIView commitAnimations];
}
尝试使用+(void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState:
-(IBAction)clickme
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[view1 setAlpha:0.0];
[UIView commitAnimations];
}
您缺少[UIView setAnimationDidStopSelector:…];)@不,我不这么认为,[UIView setAnimationDelegate:self]代码>表示发送这些消息时未显式设置选择器。是否确定?我一直认为我需要手动设置。嗯,请原谅我的经验不足。您缺少[UIView setAnimationDidStopSelector:…];)@不,我不这么认为,[UIView setAnimationDelegate:self]代码>表示发送这些消息时未显式设置选择器。是否确定?我一直认为我需要手动设置。嗯,请原谅我没有经验。