在我的代码中,我需要找到用户触摸且当前正在平移的坐标。 我根据 - Touch Coordinates from UIPanGestureRecognizer 设置了以下代码
它看起来如下:
CGPoint pos = [gestureRecognizer locationInView:[gestureRecognizer view]];
但是,此方法返回的值要么是负数,要么大于 View 自己的框架。怎么可能?我究竟做错了什么?
谢谢
最佳答案
试试这个,它给我 x 和 y 的坐标
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
CGPoint touchPoint = [gestureUp locationOfTouch:0 inView:gestureUp.view];
if (touchPoint.y <= 160)
{
if (gestureUp.direction == UISwipeGestureRecognizerDirectionUp)
{
NSLog(@"the location x...%f",touchPoint.x);
NSLog(@"the location y...%f",touchPoint.y);
}
else
{ }
}
return YES;
}
关于ios - UIPanGestureRecognizer 如何获取相对于 [gestureRecognizer View ] 的触摸坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16953495/