【问题标题】:Deactivate NSLayoutConstrain from storyboard?从情节提要中停用 NSLayoutConstrain?
【发布时间】:2015-09-15 21:27:38
【问题描述】:

我想在情节提要中设置约束,但在情节提要中将其停用 一段时间,直到发生用户交互。是否可以?

【问题讨论】:

    标签: ios storyboard nslayoutconstraint


    【解决方案1】:

    尝试将constraint.active 设置为NO,然后将其设置回YES 以重新启用它。

    如果您想在情节提要中禁用它,请转到身份检查器 (),然后单击 用户定义的运行时属性 标题下的 + 按钮。双击突出显示的行中显示“keyPath”的部分。输入active,然后取消选中复选框。

    【讨论】:

    • 我像你写的那样做了,并在更改优先级时收到此错误:'不支持将优先级从必需更改为不安装约束(反之亦然)。您通过了优先级 1,现有优先级为 1000。'Mutating a priority from required to not on an installed constraint (or vice-versa) is not supported. You passed priority 1 and the existing priority was 1000.'
    • 尝试在情节提要中将优先级设置为 999。
    • 999 优先级相同
    【解决方案2】:

    是的,这是可能的。

    1. 为该NSLayoutConstraint 创建一个IBOutlet 并将其连接到您在Storyboard 中提到的约束。

      @property (nonatomic, strong) IBOutlet UIView *myView;
      @property (nonatomic, strong) IBOutlet NSLayoutConstraint *myConstraint;
      

      myConstraint 是对 myView 的约束

    2. viewDidLoad上写这个代码:[_myView removeConstraint:_myConstraint];

    3. 然后,当发生用户交互时:[_myView addConstraint:_myConstraint];

    【讨论】:

    • 崩溃,停用后为零
    • 所以不要设置active,而是使用addremove,但要保持一个强指针
    猜你喜欢
    • 2011-01-16
    • 1970-01-01
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 2014-11-23
    • 1970-01-01
    • 2020-08-06
    • 2017-08-03
    相关资源
    最近更新 更多