我可以在运行时禁用特定子视图的自动布局吗? [英] Can I disable autolayout for a specific subview at runtime?
问题描述
我有一个需要以编程方式操作其框架的视图 - 它是一种文档视图,可以包装其内容,然后通过操纵框架原点在超级视图周围滚动和缩放.自动布局在运行时与此作斗争.
I have a view that needs to have its frame manipulated programmatically - it's a kind of document view that wraps to its content which is then scrolled and zoomed around a superview by manipulating the frame origin. Autolayout fights with this at runtime.
完全禁用自动布局似乎有点苛刻,因为它可以合理地用于处理其他视图的布局.看起来我可能想要的是某种空约束".
Disabling autolayout completely seems a bit harsh because it could reasonably be used to handle layout for the other views. It seems like what I might want is some kind of "null constraint".
推荐答案
我遇到了同样的问题.但是我已经解决了.
是的,您可以在运行时为特定的 UIView
禁用自动布局,而不是在 Xcode 4.3 及更高版本中默认设置的整个 xib 或故事板禁用它.
I had the same problem. But I have resolved it.
Yes, you can disable auto layout at runtime for a specific UIView
, instead of disabling it for the whole xib or storyboard which is set by default in Xcode 4.3 and later.
在设置子视图的框架之前,将 translatesAutoresizingMaskIntoConstraints
设置为 YES
:
Set translatesAutoresizingMaskIntoConstraints
to YES
, before you set the frame of your subview:
self.exampleView.translatesAutoresizingMaskIntoConstraints = YES;
self.exampleView.frame = CGRectMake(20, 20, 50, 50);
这篇关于我可以在运行时禁用特定子视图的自动布局吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!