gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 05:01:42 25 4
gpt4 key购买 nike

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com