Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 简单动画的问题_Iphone_Uianimation - Fatal编程技术网

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动画,并在
init
中将其初始化为
NO

那么


您需要跟踪是否有动画正在进行,如果有,则忽略单击

声明一个实例变量
BOOL动画,并在
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]表示发送这些消息时未显式设置选择器。是否确定?我一直认为我需要手动设置。嗯,请原谅我没有经验。