iPad应用程序-touchesBegan双击不正确

发布于 2025-01-04 13:28:51 字数 1063 浏览 3 评论 0原文

我有一个 UIViewController,它有 TouchBegan 函数并输出位置。

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSLog(@"in");

    NSArray *touchesArray = [touches allObjects];
    for(int i=0; i<1; i++)
    {
        UITouch *touch = (UITouch *)[touchesArray objectAtIndex:i];
        CGPoint point = [touch locationInView:touch.view];
        NSLog(@"point = %f %f",point.x,point.y);
    }
}

如果我快速双击屏幕中间,我会得到以下输出,

2012-02-12 21:47:13.522 MoreMost[479:707] in
2012-02-12 21:47:13.523 MoreMost[479:707] point = 698.000000 86.000000
2012-02-12 21:47:13.617 MoreMost[479:707] in
2012-02-12 21:47:13.619 MoreMost[479:707] point = 39.000000 22.000000

为什么第二次点击被注册为 (39,22)...这就像 iPad 的左上角。不过,我是在中间敲击的。

所以,我想通过两种方式解决这个问题:

1) somehow, not let the user double tap (however it seems even when I double tap fast, the touchesBegan function is called on two separate occassions)
2) figure out why that 2nd tap is being registered with the wrong coordinates.

I have a UIViewController that has a touchesBegan function and outputs the positions.

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSLog(@"in");

    NSArray *touchesArray = [touches allObjects];
    for(int i=0; i<1; i++)
    {
        UITouch *touch = (UITouch *)[touchesArray objectAtIndex:i];
        CGPoint point = [touch locationInView:touch.view];
        NSLog(@"point = %f %f",point.x,point.y);
    }
}

If I double tap quickly towards the middle of the screen, I get the following output

2012-02-12 21:47:13.522 MoreMost[479:707] in
2012-02-12 21:47:13.523 MoreMost[479:707] point = 698.000000 86.000000
2012-02-12 21:47:13.617 MoreMost[479:707] in
2012-02-12 21:47:13.619 MoreMost[479:707] point = 39.000000 22.000000

why is that second tap being registered as (39,22)...which is like the top left corner of the iPad. However, I was tapping in the middle.

So, I'd like to solve this in two ways:

1) somehow, not let the user double tap (however it seems even when I double tap fast, the touchesBegan function is called on two separate occassions)
2) figure out why that 2nd tap is being registered with the wrong coordinates.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2025-01-11 13:28:51

它应该是 CGPoint point = [touch locationInView:self.view];...而不是“touch.view”

It should be CGPoint point = [touch locationInView:self.view];...not "touch.view"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文