2012-12-03 33 views
8

को एनिमेट करता हूं, जब मैं UIImageView को एनिमेट करना चाहता हूं, तो UITapGestureRecognizer इसमें जोड़ा नहीं जा सकता है। क्यूं कर???UITapGestureRecognizer काम नहीं करता है जब मैं UIImageView

-(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

ओएमजी। यह पता लगाने के लिए कितने घंटे बिताए कि यह क्यों काम नहीं करता है। आपका जवाब जीवन बचतकर्ता है! – 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