2010-08-09 70 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

相關問題