加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 如何在视图中的任何位置检测到点击?

发布时间:2020-12-14 18:56:25 所属栏目:百科 来源:网络整理
导读:我有一个我的应用程序的教程,它应该只在第一次打开应用程序时显示,并应点按以解除. 我正在viewDidLoad中初始化UITapGestureRecognizer: tapper_tut = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];tapper_tut
我有一个我的应用程序的教程,它应该只在第一次打开应用程序时显示,并应点按以解除.

我正在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");
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读