ios - UIPanGestureRecognizer如何获取相对于[gestureRecognizer视图]的触摸坐标

时间:2013-06-06 04:01:49

标签: ios uigesturerecognizer

在我的代码中,我需要找到用户触摸并正在平移的坐标。 我已根据 - Touch Coordinates from UIPanGestureRecognizer

设置了以下代码

看起来如下:

    CGPoint pos = [gestureRecognizer locationInView:[gestureRecognizer view]];

但是,此方法返回的值要么是负数,要么大于视图自己的帧。怎么可能?我究竟做错了什么?

由于

1 个答案:

答案 0 :(得分:1)

试试这个,它给我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;
}