如何以编程方式删除从情节提要中添加的约束? [英] How to remove constraints programmatically that is added from storyboard?

查看:62
本文介绍了如何以编程方式删除从情节提要中添加的约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用Google搜索,但没有找到答案.所以我要问.我有一个主屏幕.当用户登录时,它将显示一个视图,如下所示现在,当用户注销并访问主页时,他将看到上面的布局,但没有中心框式布局.如果我将布局"设置为隐藏",则现在显示如下.

I have googled but not find out answer. So I need to ask. I have one home screen. When User is logged in it will display one view as like bellow Now When User logged out and visiting home page he will see above layout but without center boxed layout. If I set That layout hidden it is now displaying as follows.

我想将第三个布局移到上方一点以删除空白.

I want to move third layout to little bit above to remove white space..

我使用情节提要添加了约束.现在需要从编程中删除约束,并添加一个约束,将布局设置为波纹管优先布局.

I added constraints using storyboard. Now need to remove constraints from programming and add one constraints that will set layout to bellow first layout..

推荐答案

正如@Henit所述,您也可以为约束设置IBOutlet.

As @Henit mentioned, you can set IBOutlet for constraints as well.

例如

@property(weak, nonatomic) IBOutlet NSLayoutConstraint *viewHeight;

现在,您可以像这样删除此约束:

so now, you can remove this constraint like this:

[myView removeConstraint: viewHeight];

否则,如果要删除与视图相关的所有/多个约束,

Or else if you want to remove all / multiple constraints related to your view then,

[myView removeConstraints: constraintsArrayHere]; // custom array of constraints references
[myView removeConstraints: [myView constraints]]; //all constraints

然后,您可以使用 addConstraint addConstraints 方法以相同的方式添加新约束.

Then later you can add your new constraints in the same manner using addConstraint or addConstraints method.

有关更多详细信息,请访问Apple文档此处.

For more details go through Apple Documentation here.

希望这会有所帮助.

这篇关于如何以编程方式删除从情节提要中添加的约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆