2010-08-09 73 views
0

我有一些UIImageViews,当用户触摸时,会开始一段持续时间的动画。触发器计算++,下一次触摸时,另一个动画开始播放。 但是,如果用户触摸快速或进行双击,第一个动画直到最后一帧才会完成。 我尝试了“睡眠()”命令,但它不起作用。如何在允许下一个用户输入之前完成动画

#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; 
     }  
    } 

回答

1

当你开始动画设置用户交互禁用,当你完成后,重新启用它想:

yourImageView.userInteractionEnabled = NO;

yourImageView.userInteractionEnabled = YES;

你也可以延迟与

... 
[self performSelector:@selector(enable) withObject:yourImageView afterDelay:1.0]; 
... 


-(void)enable 
{ 
yourImageView.userInteractionEnabled = YES 
} 
+0

谢谢!我今天晚上试试。 – FredIce 2010-08-09 14:59:24

+0

谢谢,它可以像我想要的那样工作! 这比beginIgnoringInteractionEvents解决方案更好,更容易,因为只有选定的视图被禁用才能输入! – FredIce 2010-08-09 18:12:02

+0

很高兴能有所帮助。 – Gauloises 2010-08-09 19:59:14

0

启用使用UIApplications beginIgnoringInteractionEvents和endIgnoringInteractionEvents可以帮助你,当开始被称为从用户界面交互事件被忽略,这里是一个参考UIApplication ref

+0

非常感谢您的提示! – FredIce 2010-08-09 15:27:40

+0

我已经做了这样的: 情况下0: \t \t \t \t [UIApplication的sharedApplication] beginIgnoringInteractionEvents]。 \t \t \t \t [UIView beginAnimations:nil context:nil]; \t \t \t { \t \t \t \t [UIView的setAnimationCurve:UIViewAnimationCurveEaseInOut]; // geschmeidige Bewegeung \t \t \t \t [UIView setAnimationDuration:10.0f]; \t \t \t \t [UIView setAnimationDelegate:self]; \t \t \t \t ani_schwein_gross.transform = CGAffineTransformMakeTranslation(-200,10); [UIView setAnimationDidStopSelector:@selector(doneSwappingViewsAnimation:finished:context :)]; \t \t \t} \t \t \t \t [UIView的commitAnimations]; 等 动画完成 - 任何输入被禁用。 – FredIce 2010-08-09 16:16:35

+0

viewDidLoad中之前我插入: - (无效)doneSwappingViewsAnimation:(的NSString *)ID 完成:(BOOL)完成上下文:(ID)上下文 { \t [[UIApplication的sharedApplication] endIgnoringInteractionEvents]; } – FredIce 2010-08-09 16:17:57

相关问题