2012-05-12 149 views
-2

我是iPhone的初學者,我正在開發觸摸事件。我已經把這段代碼,但在觸摸不是在圖像視圖中執行我也使用imageView的scrollview,因此,不應用觸摸事件的原因。如何在圖像視圖中應用觸摸事件

我的代碼是

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    // get touch event 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint touchLocation = [touch locationInView:self.view]; 

    if ([touch view] == imagedisplay) { 
     // move the image view 
     imagedisplay.center = touchLocation; 
    } 

} 

但在不執行觸摸事件給出任何建議任何源代碼

+0

你在說什麼? 請使用正確的英文,並正確解釋 – MCKapur

回答

0

您可以使用UIGestureRecognizer。

UITapGestureRecognizer* Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTapDetected:)]; 
[Tap setDelegate:self]; 
[Tap setNumberOfTapsRequired:1]; 
[ImageView addGestureRecognizer:Tap]; 

之後,在你的功能,你可以通過使用狀態功能確定當前的TAP狀態:

-(void)imageViewTapDetected:(UItapGestureRecognizer*)Tap{ 

    switch ([Tap state]) { 
     case UIGestureRecognizerStatePossible: 

      break; 
     case UIGestureRecognizerStateBegan: 


      break; 
     case UIGestureRecognizerStateChanged: 


      break; 
     case UIGestureRecognizerStateEnded: 


      break; 
     default: 

      break; 
    } 
} 
相關問題