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

时间:2012-02-13 04:11:10

标签: ipad touchesbegan

我有一个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 个答案:

答案 0 :(得分:0)

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