UITapGeatureRecogniser 不适用于 2 个标签
Posted
技术标签:
【中文标题】UITapGeatureRecogniser 不适用于 2 个标签【英文标题】:UITapGeatureRecogniser is not working on 2 labels 【发布时间】:2013-12-17 05:50:42 【问题描述】:我试图在两个标签上使用两个TapGestures
,但它总是显示最后一个 TapGesture 的结果。我的代码如下:
[write_review_label addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(open_view:)]];
[map_image addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(open_view:)]];
write_review_label.tag = 1;
map_image.tag = 2;
-(void)open_view:(UITapGestureRecognizer *)recog1
NSLog( @"recog1.view.tag == %d",recog1.view.tag);
if (recog1.view.tag==2)
[self performSegueWithIdentifier:@"mapsegue" sender:self];
else
[self performSegueWithIdentifier:@"loginsegue" sender:self];
【问题讨论】:
【参考方案1】:默认情况下,标签和图像视图的用户交互是禁用的,
启用它。
[write_review_label setUserInteractionEnabled:YES];
[map_image setUserInteractionEnabled:YES];
【讨论】:
【参考方案2】:您需要启用标签的用户交互,例如:
write_review_label.userInteractionEnabled = YES;
map_image.userInteractionEnabled = YES;
【讨论】:
以上是关于UITapGeatureRecogniser 不适用于 2 个标签的主要内容,如果未能解决你的问题,请参考以下文章