Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何取消UIlabel的UItouchevent_Ios_Objective C - Fatal编程技术网

Ios 如何取消UIlabel的UItouchevent

Ios 如何取消UIlabel的UItouchevent,ios,objective-c,Ios,Objective C,我不希望用户点击UILabel时触发ToucheSBegind事件。 我怎样才能做到?。 我们将通知您任何帮助。请提前感谢。禁用标签上的用户交互,如 [yourLabel setUserInteractionEnabled:NO]; myLabel.userInteractionEnabled=否 在界面生成器中。 单击UILabel。然后是属性选项卡。在查看下,确保未选中用户交互 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent

我不希望用户点击UILabel时触发ToucheSBegind事件。 我怎样才能做到?。
我们将通知您任何帮助。请提前感谢。

禁用标签上的用户交互,如

[yourLabel setUserInteractionEnabled:NO];

myLabel.userInteractionEnabled=否

在界面生成器中。 单击UILabel。然后是属性选项卡。在查看下,确保未选中用户交互

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    //This will ignore all UILabel touch event
    if ([[touch.view class] isKindOfClass:[UILabel class]]) return;

   //do something for touch event for other UIElements




}


尝试检查您正在触摸的当前视图是否符合UILabel的需要

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    if ([[touch.view class] isSubclassOfClass:[UILabel class]])
    {
        if (touch.view == yourLabel) {
            //Dont do anything if this is your label.
        }
    }
}

您应该为标签启用用户输入

[yourLabel setUserInteractionEnabled:YES];

您只需使用标签框签入接触点即可。

您是否使用界面构建器您在何处使用了touchUpInside方法?您是否覆盖了UILabel并提供了它,或者它位于UILabel的超级视图中?我在UIViewController中有UILabel并为其创建了IBOutlet。我没有覆盖它。如果以下解决方案无效,则您的问题不清楚。你到底想干什么?你试着约会什么?显示相关代码。在我启用userInteractionEnabled后:是的,我可以在UITouchEvent内捕获UIlabel。。