gpt4 book ai didi

iphone - UIGestureRecognizer 触发两次?

转载 作者:行者123 更新时间:2023-12-03 18:21:56 36 4
gpt4 key购买 nike

我已经在 View Controller 的 viewDidLoad 上设置了 UITapGestureRecognizer,但不知何故,它会为单次点击触发两次选择器方法。

UITapGestureRecognizer *g = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openInMapsApp:)] autorelease];
[self.mapView addGestureRecognizer:g];

我的方法:

-(void)openInMapsApp:(UIGestureRecognizer*)g {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
message:@"This will open this location in the Maps application. Continue?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];
[alertView show];
[alertView release];
}

最佳答案

手势识别器发送具有不同手势状态的 Action 。所以这不是一个错误。解决方法是:

 UITapGestureRecognizer *g = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openInMapsApp:)] autorelease];
[self.mapView addGestureRecognizer:g];
<小时/>
-(void)openInMapsApp:(UIGestureRecognizer*)g {
if(g.state != UIGestureRecognizerStateRecognized)
return;
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""
message:@"This will open this location in the Maps application. Continue?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK",nil];
[alertView show];
[alertView release];
}

关于iphone - UIGestureRecognizer 触发两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3224053/

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