简体   繁体   English

如何在AutoLayout中设置UIView的框架?

[英]How to set frame of UIView in AutoLayout?

First of all I have read this answer . 首先,我已经阅读了这个答案

But somehow, we have requirement to change view programatically. 但是以某种方式,我们需要以编程方式更改视图。 And we have use Autolayout all over. 而且我们已经使用了Autolayout。

I have code something like this, 我有这样的代码,

 self.containerView.frame = CGRectMake(x,y,30,30);

This doesn't work. 这行不通。 Though I can hide/show border. 虽然我可以隐藏/显示边框。 But I cannot change frame. 但是我不能改变框架。

Please suggest any hack if not exact solution. 如果不是确切的解决方案,请提出任何建议。

hope this will help 希望这会有所帮助

when auto layout is ON you can't update the frame or bound of an ui element. 如果启用自动版式,则无法更新ui元素的框架或边界。

so you should set the auto layout OFF and then change the frame of your element or if you already put lot of constraints for managing your view and don't want to delete them , you should update your constraint in such a way that constraint update your view. 因此,您应该将自动布局设置为OFF,然后更改元素的框架,或者如果您已经放置了很多用于管理视图的约束并且不想删除它们,则应该以更新约束的方式更新约束视图。

second, if some object add programmatically in your view then your previously define constraint does not work on it .so for it you have to add constraint programmatically. 其次,如果某个对象在您的视图中以编程方式添加,则您先前定义的约束不起作用。因此,您必须以编程方式添加约束。

You can use the Autolayout Constraints tool, to make this process easier. 您可以使用“自动布局约束”工具来简化此过程。

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

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