我已经在我的视图控制器的viewDidLoad上设置了一个UITapGestureRecognizer,但不知怎的,它只为一次点击两次激活选择器方法.
UITapGestureRecognizer *g = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openInMapsApp:)] autorelease];
[self.mapView addGestureRecognizer:g];
Run Code Online (Sandbox Code Playgroud)
我的方法:
-(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];
}
Run Code Online (Sandbox Code Playgroud)
小智 19
手势识别器以不同的手势状态发送动作.所以这不是一个错误.解决方法是:
UITapGestureRecognizer *g = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openInMapsApp:)] autorelease];
[self.mapView addGestureRecognizer:g];
Run Code Online (Sandbox Code Playgroud)
-(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];
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我有一个双重UIAlertView上升.如上面的Nicolas Rostov所示,这对我有用.无论是UIGestureRecognizerStateEnded与UIGestureRecognizerStateRecognized美国创建了一个新alertView时,[alertView show]该块被使用.随着// [alertView show]注释掉,它们仍然出现在控制台上,但只发生了一个动作.
-(void) handleTapGesture:(UIGestureRecognizer*)sender{
if(sender.state != UIGestureRecognizerStateRecognized)
return;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5420 次 |
| 最近记录: |