-2

我是 iPhone 的初学者,我正在处理触摸事件。我已经放了这段代码,但是在图像视图中没有执行触摸我还在 imageView 上使用了滚动视图,因此不应用触摸事件的原因。

我的代码是

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

}

但在那不执行触摸事件中给出任何建议任何源代码

4

1 回答 1

0

您可以使用 UIGestureRecognizer。

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

之后,在您的函数中,您可以使用 state 函数确定当前的点击状态:

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

    switch ([Tap state]) {
        case UIGestureRecognizerStatePossible:

            break;
        case UIGestureRecognizerStateBegan:


            break;
        case UIGestureRecognizerStateChanged:


            break;
        case UIGestureRecognizerStateEnded:


            break;
        default:

            break;
    }
}
于 2012-05-12T15:30:47.920 回答