Get touch points in UIScrollView through UITapGestureRecognizer

落花浮王杯 提交于 2019-12-11 03:28:32

问题


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'...
}


来源:https://stackoverflow.com/questions/6936314/get-touch-points-in-uiscrollview-through-uitapgesturerecognizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!