iOS如何确定屏幕是否已被点击

时间:2012-07-20 18:59:09

标签: ios cocoa-touch ios5 touch uigesturerecognizer

我正在使用iOS 5.x SDK,我想确定是否已点击屏幕

现在只需要建立一个NSLog就可以,但我不知道从哪里开始

2 个答案:

答案 0 :(得分:3)

通常使用gesture recognizers,例如,

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOnView:)];
[self.view addGestureRecognizer:tap];

然后你有一个方法:

- (void)tapOnView:(UITapGestureRecognizer *)sender
{
    CGPoint location = [sender locationInView:self.view];
    NSLog(@"Tap at %1.0f, %1.0f", location.x, location.y);
}

答案 1 :(得分:1)

您可能希望从实施touchesBegan:withEvent:touchesMoved:withEvent:touchesEnded:withEvent:touchesCancelled:withEvent:开始。

您可以在此处详细了解:UIResponder Class Reference