繁体   English   中英

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

[英]ios - UIPanGestureRecognizer how to get the touched coordinate relative to [gestureRecognizer view]

在我的代码中,我需要找到用户触摸过且当前正在平移的坐标。 我已基于以下代码设置了以下代码-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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM