【问题标题】:iPad app - touchesBegan double tapping not correctiPad 应用程序 - touchesBegan 双击不正确
【发布时间】:2012-02-13 04:11:09
【问题描述】:

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

- (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.

【问题讨论】:

  • 1) 当您点击两次时,touchesBegan:withEvent: 将被调用两次。 (就是这样工作的) 2)我怀疑你双击的每次点击都落在两个不同的视图中,不要问我怎么不知道。但最合理的解决方案是将您的位置索引到已知视图,例如:locationInView:self.view 而不是 touch.view,这将是触摸通过命中测试的任何视图。
  • 是的,这行得通。不知道为什么我把 touch.view,大声笑。谢谢!

标签: ipad touchesbegan


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多