-1

我想在兩個標籤上使用兩個TapGestures,但它總是顯示上一個TapGesture的結果。我的代碼如下:UITapGeatureRecogniser不能在2個標籤上工作

[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

默認情況下,用戶交互是禁用標籤和ImageView的,

使其啓用。

[write_review_label setUserInteractionEnabled:YES]; 
[map_image setUserInteractionEnabled:YES]; 
0

您需要啓用像標籤的用戶交互:

write_review_label.userInteractionEnabled = YES; 
map_image.userInteractionEnabled = YES;