簡體   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