2012-03-01 32 views
2

我試圖檢測觸摸,而我的UIImageView正在進行動畫製作。 觸摸檢測在動畫開始之前工作,並且一旦它停止,但不在期間。UIViewAnimationOptionAllowUserInteraction不起作用

我試過添加UIViewAnimationOptionAllowUserInteraction,但它 似乎根本沒有效果!

任何人都可以指向正確的方向嗎?

代碼:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [touches anyObject]; 
    NSLog(@"tag=%@", [NSString stringWithFormat:@"%i", touch]); 
    if ([touch view] == itemCoke) 
    { 
     NSLog(@"Coke Touched"); 
    } 

} 

- (IBAction)removeItemButton:(id)sender { 
    NSLog(@"Pushed"); 


    [UIView animateWithDuration:5 
          delay:0.0   
         options:UIViewAnimationOptionAllowUserInteraction 
        animations:^ 
          { 
           itemCoke.transform = CGAffineTransformRotate(itemCoke.transform, (M_PI*-0.5)); 
           itemCoke.frame = CGRectMake(50, 50, 50, 50); 
          } 
        completion:^(BOOL finished){}]; 
} 

感謝您的諮詢!

回答

8

交互不起作用的原因是,本質上UIImageView不是它看起來的地方。只有視圖的CALayer的表示層正在屏幕上進行動畫。視圖已經立即到達目的地。這使交互更加困難。 You will likely find this answer helpful.

0

這應該做的伎倆

-(UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{ 
if ([[self.layer presentationLayer] hitTest:point]) { 
    return self; 
} 
return [super hitTest:point withEvent:event];} 

寫在你的UIView