繁体   English   中英

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

[英]iOS how to determine if the screen has been tapped

我正在使用iOS 5.x SDK,我想确定屏幕是否被轻按

就目前而言,建立一个NSLog很好,但是我不知道从哪里开始

通常使用手势识别器 ,例如

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);
}

您可能想从实现touchesBegan:withEvent:touchesMoved:withEvent:touchesEnded:withEvent:touchesCancelled:withEvent:

您可以在这里阅读有关它的更多信息: UIResponder类参考

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM