如何让动画在允许下一次用户输入之前完成
我有一些 UIImageViews,当用户触摸时,会开始具有一定持续时间的动画。触发器计数 ++,并在下一次触摸时开始播放另一个动画。 但是,如果用户快速触摸或进行双击,则第一个动画直到最后一帧才会完成。 我尝试了“sleep()”命令,但它不起作用。
#pragma mark HenneAnimation
if([touch view] == ani_Henne){
//trigger strats with zero
switch (trigHenne) {
case 0:
//firstanimation 1 sec
ani_Henne.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"ani_Henne01.png"],
[UIImage imageNamed:@"ani_Henne01.png"],
[UIImage imageNamed:@"ani_Henne02.png"],
[UIImage imageNamed:@"ani_Henne01.png"],
[UIImage imageNamed:@"ani_Henne01.png"],nil];
ani_Henne.animationDuration = 1;
ani_Henne.animationRepeatCount = 1;
[ani_Henne startAnimating];
[self.view addSubview:ani_Henne];
trigHenne++;
break;
case 1:
//second animation 1 sec
ani_Henne.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"ani_Henne03.png"],
[UIImage imageNamed:@"ani_Henne05.png"],
[UIImage imageNamed:@"ani_Henne03.png"],
[UIImage imageNamed:@"ani_Henne03.png"],
[UIImage imageNamed:@"ani_Henne04.png"],
[UIImage imageNamed:@"ani_Henne05.png"],
[UIImage imageNamed:@"ani_Henne03.png"],nil];
ani_Henne.animationDuration = 3;
ani_Henne.animationRepeatCount = 1;
[ani_Henne startAnimating];
[self.view addSubview:ani_Henne];
trigHenne++;
break;
case 2:
[self.view bringSubviewToFront:ani_Henne];
ani_Henne.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"ani_Henne06.png"],
[UIImage imageNamed:@"ani_Henne07.png"],
[UIImage imageNamed:@"ani_Henne06.png"],
[UIImage imageNamed:@"ani_Henne06.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne09.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne09.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne07.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne09.png"],
[UIImage imageNamed:@"ani_Henne08.png"],nil];
ani_Henne.animationDuration = 2.75;
ani_Henne.animationRepeatCount = 1;
[ani_Henne startAnimating];
[self.view addSubview:ani_Henne];
trigHenne++;
break;
case 3:
trigHenne=0;
// etc. animations
break;
default:
break;
}
}
I have some UIImageViews and when the user is touching, an animation with a certain duration starts. A trigger counts ++ and with the next touch another animation starts to play.
But if the user touches to fast or make a doubletouch the first animation does not finish until the last frame.
I tried the "sleep()" command, but it does not work.
#pragma mark HenneAnimation
if([touch view] == ani_Henne){
//trigger strats with zero
switch (trigHenne) {
case 0:
//firstanimation 1 sec
ani_Henne.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"ani_Henne01.png"],
[UIImage imageNamed:@"ani_Henne01.png"],
[UIImage imageNamed:@"ani_Henne02.png"],
[UIImage imageNamed:@"ani_Henne01.png"],
[UIImage imageNamed:@"ani_Henne01.png"],nil];
ani_Henne.animationDuration = 1;
ani_Henne.animationRepeatCount = 1;
[ani_Henne startAnimating];
[self.view addSubview:ani_Henne];
trigHenne++;
break;
case 1:
//second animation 1 sec
ani_Henne.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"ani_Henne03.png"],
[UIImage imageNamed:@"ani_Henne05.png"],
[UIImage imageNamed:@"ani_Henne03.png"],
[UIImage imageNamed:@"ani_Henne03.png"],
[UIImage imageNamed:@"ani_Henne04.png"],
[UIImage imageNamed:@"ani_Henne05.png"],
[UIImage imageNamed:@"ani_Henne03.png"],nil];
ani_Henne.animationDuration = 3;
ani_Henne.animationRepeatCount = 1;
[ani_Henne startAnimating];
[self.view addSubview:ani_Henne];
trigHenne++;
break;
case 2:
[self.view bringSubviewToFront:ani_Henne];
ani_Henne.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"ani_Henne06.png"],
[UIImage imageNamed:@"ani_Henne07.png"],
[UIImage imageNamed:@"ani_Henne06.png"],
[UIImage imageNamed:@"ani_Henne06.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne09.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne09.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne07.png"],
[UIImage imageNamed:@"ani_Henne08.png"],
[UIImage imageNamed:@"ani_Henne09.png"],
[UIImage imageNamed:@"ani_Henne08.png"],nil];
ani_Henne.animationDuration = 2.75;
ani_Henne.animationRepeatCount = 1;
[ani_Henne startAnimating];
[self.view addSubview:ani_Henne];
trigHenne++;
break;
case 3:
trigHenne=0;
// etc. animations
break;
default:
break;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您开始设置动画时,请禁用用户交互,完成后,重新启用它,如下所示:
yourImageView.userInteractionEnabled = NO;
yourImageView.userInteractionEnabled = YES;
您还可以延迟启用
When you begin to animate set the userinteraction disabled, and when you are done, reenable it like:
yourImageView.userInteractionEnabled = NO;
yourImageView.userInteractionEnabled = YES;
you could also delay the enabling with
使用 UIApplications beginIgnoringInteractionEvents 和 endIgnoringInteractionEvents 可能会对您有所帮助,当调用 begin 时,用户的 UI 交互事件将被忽略,这里有一个参考 UIApplication 参考
Using UIApplications beginIgnoringInteractionEvents and endIgnoringInteractionEvents might help you, when begin is called UI interaction events from user are ignored, here is a reference UIApplication ref