我有一些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;
}
}
答案 0 :(得分:1)
当你开始设置动画时,禁用了userinteraction,当你完成后,重新启用它:
yourImageView.userInteractionEnabled = NO;
yourImageView.userInteractionEnabled = YES;
您还可以使用
延迟启用...
[self performSelector:@selector(enable) withObject:yourImageView afterDelay:1.0];
...
-(void)enable
{
yourImageView.userInteractionEnabled = YES
}
答案 1 :(得分:0)
使用UIApplications beginIgnoringInteractionEvents和endIgnoringInteractionEvents可能对您有所帮助,当调用begin时,将忽略来自用户的UI交互事件,这里是引用UIApplication ref