iphone - 如何检测 View 中任意位置的点击?

标签 iphone ios objective-c xcode

我的应用程序有一个教程,它应该只在应用程序第一次打开时显示,点击它可以关闭。

我正在我的 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/

相关文章:

objective-c - 动态附加一个变量属性名

iphone - NSManagedObjectContext 没有正确刷新

iphone - 插入 UIImageView 作为 subview 滞后

ios - 错误 : Target failed to run: Permission to debug com. apple.Preferences 被拒绝

ios - 当 ios 中该部分数据为空时,我如何删除 uitableview 部分?

objective-c - 如何在 Xcode 4.2 中创建 Shell 脚本目标?

ios - Objective-C . 追踪无法识别的选择器

ios - 为什么按下 UISearchbar 上的取消按钮时会出现 UIKeyboard?

ios - 以编程方式为自定义UIViewController设置 Storyboard ID?

ios - 制作一些可拖动的 UIView