我的应用程序有一个教程,它应该只在应用程序第一次打开时显示,点击它可以关闭。
我正在我的 viewDidLoad 中初始化一个 UITapGestureRecognizer:
tapper_tut = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
tapper_tut.cancelsTouchesInView = FALSE;
[self.view addGestureRecognizer:tapper_tut];
我有一个 IBAction 来检测点击并将教程设置为隐藏:
- (IBAction)dismiss_tut{
if (????????????????) {
_tutorial.hidden = YES;
}
}
但我不知道在 if 语句条件中放入什么,或者这是否是解决此问题的正确方法。
我如何在点击时关闭 UIImageView?
最佳答案
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[self.view addGestureRecognizer:gr];
// if not using ARC, you should [gr release];
// mySensitiveRect coords are in the coordinate system of self.view
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self.view];
if (CGRectContainsPoint(mySensitiveRect, p)) {
NSLog(@"got a tap in the region i care about");
} else {
NSLog(@"got a tap, but not where i need it");
}
}
关于iphone - 如何检测 View 中任意位置的点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19509113/