如何获得相对于[gestureRecognizer视图]的触摸坐标



在我的代码中,我需要找到用户触摸和当前平移的坐标。我基于UIPanGestureRecognizer

中的触摸坐标设置了以下代码

内容如下:

    CGPoint pos = [gestureRecognizer locationInView:[gestureRecognizer 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;
}

最新更新