简体   繁体   English

以编程方式更改约束后,视图不会更新

[英]View doesn't update after changing constraints programmatically

I want to change the relation of a constraint programmatically that is why I create a new one and replace the old one with it. 我想以编程方式更改约束的关系,这就是为什么我创建一个新约束并将其替换为旧约束的原因。 I have an IBOutlet of my constraint which I want to change. 我有一个要更改的约束的IBOutlet。 As because I am using multi-os-engine my code for updating the constraint looks a little bit different to normal objectiv-c or swift. 因为我使用的是multi-os-engine,所以我更新约束的代码看起来与普通的objectiv-c或swift有点不同。

setBasketTopConstraint(
        NSLayoutConstraint.constraintWithItemAttributeRelatedByToItemAttributeMultiplierConstant(
            basketTopConstraint().firstItem(),
            basketTopConstraint().firstAttribute(),
            NSLayoutRelation.LessThanOrEqual,
            basketTopConstraint().secondItem(),
            basketTopConstraint().secondAttribute(),
            basketTopConstraint().multiplier(),
            basketTopConstraint().constant()
    )
);

My problem is, that I can't see any effect from changing the constraint. 我的问题是,更改约束后看不到任何影响。 It seems like I need to refresh my view somehow. 似乎我需要以某种方式刷新自己的观点。 I called view().setNeedsLayout() and view().layoutIfNeeded() but with no success. 我调用了view().setNeedsLayout()view().layoutIfNeeded()但没有成功。

Any advice? 有什么建议吗?

You need to ensure that you: 您需要确保自己:

  1. Install any new constraints and activate them 安装任何新约束并激活它们
  2. Deactivate and/or remove any old constraints 停用和/或删除所有旧约束
  3. Call layoutIfNeeded() 调用layoutIfNeeded()

您是否尝试添加代码以更改视图将布局子视图的约束?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM