检查UIView是否被触摸?

发布于 2024-10-04 08:31:33 字数 59 浏览 1 评论 0原文

嘿,我希望能够检查用户是否触摸了我的 UIView,这样我就可以关闭我的选择器,我实际上该怎么做?谢谢!

Hey, I want to be able to check if user touches my UIView so I can dismiss my picker how can I do it actually? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趴在窗边数星星i 2024-10-11 08:31:33

尝试将 UITapGestureRecognizer 添加到包含 UIView 的 UIViewController 子类的 viewDidLoad 中的 UIView。它看起来像这样:

- (void)viewDidLoad {
    [super viewDidLoad];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(viewTapped:)];
    tap.numberOfTapsRequired = 1;
    [self.aView addGestureRecognizer:tap];
    [tap release];
}

然后为水龙头实现一个处理程序,根据上面的代码,它看起来像这样:

-(void)viewTapped:(UITapGestureRecognizer *)recognizer {
    //Add in your picker dismissal code here
}

希望这有帮助,

贾斯汀

Try adding a UITapGestureRecognizer to your UIView class in the viewDidLoad of the UIViewController subclass that contains your UIView. It would look something like this:

- (void)viewDidLoad {
    [super viewDidLoad];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self  action:@selector(viewTapped:)];
    tap.numberOfTapsRequired = 1;
    [self.aView addGestureRecognizer:tap];
    [tap release];
}

Then implement a handler for the tap which, based on the above code, would look like this:

-(void)viewTapped:(UITapGestureRecognizer *)recognizer {
    //Add in your picker dismissal code here
}

Hope this helps,

Justin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文