我该如何关闭自动布局从code一个看法? [英] How do I turn off Auto Layout for a view from code?
问题描述
我还没有被使用自动布局,因为我需要支持的iOS 5,现在我得到一个NSInternalInconsistencyException当我推控制器:
I haven't been using Auto Layout because I need to support iOS 5. I'm now getting an NSInternalInconsistencyException when I push a controller:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'Auto Layout still required after executing -layoutSubviews.
SGBExampleView's implementation of -layoutSubviews needs to call super.'
我的layoutSubviews实施的确实的调用[超级layoutSubviews],所以这是无益的。看来,事情已经开启自动布局我的看法;我想再次将其关闭。然而,一切我能找到,说怎么关闭它说,从IB这样做。我不使用IB。我该如何关闭自动布局从code视图?
My implementation of layoutSubviews does call [super layoutSubviews], so that's unhelpful. It seems that something has turned on Auto Layout for my view; I'd like to turn it off again. However, everything I can find that says how to turn it off says to do so from IB. I don't use IB. How do I turn off Auto Layout for a view from code?
更新:的
UPDATE:
这个问题是不是重复的其他所属专门一个UITableViewCell子类,并设置 translatesAutoresizingMaskIntoConstraints
YES或NO没有任何效果。 的
This question is not a duplicate as the other pertains specifically to a UITableViewCell subclass, and setting translatesAutoresizingMaskIntoConstraints
to either YES or NO has no effect.
推荐答案
我最近被添加到与汽车布局发起的一个项目,但我需要动态地调整在code某些帧。这是我做了什么不是由自动生成运行时间的限制(自动布局提供)被削弱:
I've recently been added to a project that was initiated with auto layout, but I needed to dynamically adjust some frames in code. This is what I did to not be impaired by automatically generated run time constraints (courtesy of auto layout):
1)不要在界面生成器布局视图或组件。
1) Do NOT have views or components laid out in interface builder.
2)添加您的看法纯属编程开始分配/ init和适当地设置帧。
2) Add your views purely programmatically starting with alloc/init and setting their frames appropriately.
3)完成。
希望帮助!
PS。你也可以尝试从剥离的意见与限制:
ps. you can also experiment with stripping constraints from views with:
[查看removeConstraints:view.constraints]
但我已经有更多的运气与纯code的方法。
[view removeConstraints:view.constraints] but i've had more luck with the pure code approach.
这篇关于我该如何关闭自动布局从code一个看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!