Get touch points in UIScrollView through UITapGest

2019-07-13 15:09发布

问题:

i am using UIScrollview and UITapGestureRecognizer for getting touch event.

Now, i want x and y coordinates for my touch position.

any help Please?

回答1:

In your gesture recognizer handler:

 CGPoint location = [gestureRecognizer locationInView:gestureRecognizer.view];

you could specify a different view, if you need it.

or u can use this also It belongs in a View rather than ViewController, and would look something like this:

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)evt {
  UITouch *touch=[touches anyObject];
  CGPoint pt=[touch locationInView:self];
  // ...make your button at 'pt'...
}