gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:52:16 25 4
gpt4 key购买 nike

在我的代码中,我需要找到用户触摸且当前正在平移的坐标。我根据 - 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com