如何仅关闭一个视图(不是整个故事板)的自动布局 xcode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20448037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to turn off auto layout for only one view ( not the whole story board ) xcode
提问by user2988343
I just want to turn the auto layout feature for one view only in mystoryboard . is that possible and if yes , how do I do that . I'm using xcode 4.6.3
我只想在 mystoryboard 中为一个视图打开自动布局功能。这可能吗,如果是,我该怎么做。我正在使用 xcode 4.6.3
回答by user2431285
From the answer given by MuhammadAamirAli here, its possible. Here is a snapshot code from his answer, which I found useful.
从 MuhammadAamirAli here给出的答案来看,这是可能的。这是他的回答中的快照代码,我发现它很有用。
[self.benchmarkButton removeFromSuperview];
[self.benchmarkButton setTranslatesAutoresizingMaskIntoConstraints:YES];
[self.benchmarkButton setFrame:CGRectMake(20, self.benchmarkButton.frame.origin.y+40, 260, 30)];
[self.benchmarksView addSubview:self.benchmarkButton];
回答by Jeremiah Smith
This is not tested yet, but it could work and override the auto-layout done in interface builder, it also lets you specify a views array: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AutoLayoutinCode/AutoLayoutinCode.html
这尚未经过测试,但它可以工作并覆盖界面构建器中完成的自动布局,它还允许您指定视图数组:https: //developer.apple.com/library/ios/documentation/UserExperience/Conceptual/ AutolayoutPG/AutoLayoutinCode/AutoLayoutinCode.html
回答by bilobatum
Technically, everyone is right about not being able to turn off Auto Layout for individual scenes in storyboard. However, even if the global "switch" for Auto Layout is turned on in storyboard, you can still use autoresizing masks (i.e., the springs-and-struts system) anywhereyou want. Although the system will convert the masks into "auto-resizing" constraints behind the scenes, you won't have to deal with the constraints directly.
从技术上讲,每个人都不能为故事板中的单个场景关闭自动布局。但是,即使在故事板中打开了自动布局的全局“开关”,您仍然可以在任何需要的地方使用自动调整大小的蒙版(即 springs-and-struts 系统)。尽管系统会在幕后将蒙版转换为“自动调整大小”约束,但您不必直接处理这些约束。
Just make sure that when you alloc/init a view programmatically, you set its translatesAutoresizingMaskIntoConstraints property to YES.
只需确保以编程方式分配/初始化视图时,将其 translatesAutoresizingMaskIntoConstraints 属性设置为 YES。