2012-12-03 14 views
8

UIImageViewをアニメーション化するときに、UITapGestureRecognizerが追加されても機能しません。なぜ???UIImageViewをアニメーション化するとUITapGestureRecognizerが機能しない

-(void) testTap:(id)sender { 
    NSLog(@"Test tap..."); 
} 

-(void) testSlide { 
    UITapGestureRecognizer* testTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(testTap:)] autorelease]; 
    testTap.numberOfTapsRequired = 2; 

    UIImageView* imageView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tip_slide"]] autorelease]; 
    [imageView setFrame:CGRectMake(40, 40, 200, 200)]; 
    imageView.userInteractionEnabled = YES; 
    imageView.multipleTouchEnabled = YES; 
    [imageView addGestureRecognizer:testTap]; 

    [self.view addSubview:imageView]; 


    // When I add the following code, the UITapGestureRecognizer will not work. WHY??? 
    imageView.alpha = 0; 
    CGAffineTransform t = imageView.transform; 
    if (CGAffineTransformIsIdentity(t)) { 
     UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut; 
     [UIView animateWithDuration:1.0 delay:0 options:options animations:^{ 
      imageView.alpha = 1.0; 
     } completion:^(BOOL finished) { 
      if (finished) { 
       [UIView animateWithDuration:1.0 delay:2.0 options:options animations:^{ 
       imageView.alpha = 0.4; 
       } completion:^(BOOL finished) { 
        if (finished) { 
         [imageView removeFromSuperview]; 
        } 
       }]; 
      } 
     }]; 
    } 
} 

答えて

22

アニメーション中にユーザーの操作を許可する必要があります。

UIViewAnimationOptions options = UIViewAnimationCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction; 
+0

OMG。それがなぜ機能しないのか理解するために何時間も費やした。あなたの答えは命の恩人です! – GeneCode

3

だけスウィフトのためにこれに追加するには...このようなものは...非常によく 使用.AllowUserInteractionに動作します。

UIView.animateWithDuration(0.4, delay: 1.5, usingSpringWithDamping: 0.5, initialSpringVelocity: 20, options: UIViewAnimationOptions.AllowUserInteraction, animations: 
       {self.frame = originalFrame}, completion: nil) 
+1

あなたは多くのアニメーションのオプションを持っている場合は、このようにそれらを渡すことができます。 '' 'UIView.animateWithDuration(1.0、 遅延:0.2、 オプション:[.CurveEaseOut、.REPEAT、.Autoreverse、.AllowUserInteraction]、 アニメーション:{ self.leftArrowImageView.alpha = 0.0 }、完了:なし) '' ' – Mallox

関連する問題