简单动画的问题
我在按钮上使用动画,单击第一次显示视图,第二次隐藏视图。 这是我用于隐藏视图的代码,
-(IBAction)clickme
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[view1 setAlpha:0.0];
[UIView commitAnimations];
}
类似的代码用于显示视图。
但是,当用户一次又一次单击按钮多次时,就会出现问题......意味着我的动画使用了 2 秒,但如果用户在动画期间按下相同的按钮,则输出结果非常糟糕。
我不想在动画期间禁用该按钮。
还有其他办法吗?
I am using animation on a button click first time show a view and second ti me hide a view.
here is my code for hiding a view
-(IBAction)clickme
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:self];
[view1 setAlpha:0.0];
[UIView commitAnimations];
}
similar code is there for showing the view.
But the problem arises when user click the button many times again and again....means i am using 2 seconds for my animation but if user presses the same button in during the animation then the output result is very bad.
I don't want to disable that button during the period of animation.
Is there any other way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要跟踪是否有动画正在进行,如果有则忽略点击。
在类头中声明一个实例变量
BOOL animating;
,并在init
中将其初始化为NO
。然后,
You need to keep track of whether there's an animation going on, and ignore the click if it is.
Declare an instance variable
BOOL animating;
in your class header, and initialise it toNO
in yourinit
.Then,
尝试使用 + (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState:
try to use + (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState: