Ios 点击UILabel上的手势不在文本上方触发

Ios 点击UILabel上的手势不在文本上方触发,ios,objective-c,Ios,Objective C,我现在有个奇怪的问题。我创建了一个UILabel,并设置了一个点击手势。它只有在我点击文本上方的空白处时才会触发。。当我点击标签上的文字时,这个手势永远不会触发 UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake((sideMenuViewWidth - sideMenuViewWidth * 0.9) / 2, hPos, largestLabelWidth * 1.2, 30)]; lbl.text = conte

我现在有个奇怪的问题。我创建了一个UILabel,并设置了一个点击手势。它只有在我点击文本上方的空白处时才会触发。。当我点击标签上的文字时,这个手势永远不会触发

    UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake((sideMenuViewWidth - sideMenuViewWidth * 0.9) / 2, hPos, largestLabelWidth * 1.2, 30)];
    lbl.text = content.itemName;
    [lbl setTextAlignment:NSTextAlignmentRight];
    [lbl setTextColor:[UIColor whiteColor]];
    [lbl setFont:[UIFont fontWithName:@"TrebuchetMS-bold" size:18]];
    lbl.userInteractionEnabled = YES;

    UITapGestureRecognizer *gesture =[[UITapGestureRecognizer alloc] initWithTarget:targetViewController action:content.itemTapHandler];
    gesture.numberOfTapsRequired = 1;

    [lbl addGestureRecognizer:gesture];
在我的代码块中有什么看起来不正确的吗


非常感谢

原来问题是子视图索引不正确。它上面还有一个子视图正在拦截水龙头。使用以下代码段修复了此问题:

[self.view bringSubviewToFront:lbl];

我觉得不错。我刚刚试过你的代码稍微修改一下:更改了框架、背景颜色和手势识别器的目标/选择器,结果成功了。起初我认为,您的框架可能太小,但UILabel会将其内容剪裁到边界,因此您可能会注意到。感谢检查:结果表明我的子视图索引不正确,并且在它上面有另一个子视图。通过将标签移动到顶部来修复它。哦,我明白了:很高兴,你解决了你的问题:你可以自己留下答案并接受它。或者我不知道。对于其他用户来说,最好表明问题已经解决: