ios Xcode 复选框“将自动调整大小掩码转换为约束”在哪里

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17018533/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:51:35  来源:igfitidea点击:

Where is the Xcode checkbox "Translates Autoresizing Mask Into Constraints"

iosxcodemacosautolayoutnslayoutconstraint

提问by bobsmells

In one of the WWDC 2012 videos, Auto Layout By Example, they demo an OS X app using Autolayout, and at about 7 or 8 minutes in, he shows how for a single view, you can uncheck a box in the Attributes Inspector, and the box is called something like "Translates Autoresizing Mask Into Constraints". Now, I'm well aware of the code equivalent of this box, the translatesAutoresizingMaskIntoConstraintsboolean, but I can't seem to find this checkbox anywhere in either iOS or OS X projects. My project uses Autolayout. I really would like this checkbox, because one of things I'm struggling with in learning Autolayout (and converting a springs/struts app to AL) is the million constraints Xcode has generated for each view, and how to clean them up and sensibly override some/all in code. What I'd like in order to do this conversion one view at a time is to turn off those auto-generated constraints.

在 WWDC 2012 的一个视频中,Auto Layout By Example,他们演示了一个使用 Autolayout 的 OS X 应用程序,在大约 7 或 8 分钟后,他展示了如何在单个视图中取消选中属性检查器中的一个框,以及该框称为“将自动调整大小的蒙版转换为约束”之类的东西。现在,我很清楚这个框的等价代码,translatesAutoresizingMaskIntoConstraints布尔值,但我似乎无法在 iOS 或 OS X 项目中的任何地方找到此复选框。我的项目使用自动布局。我真的很喜欢这个复选框,因为我在学习自动布局(并将 springs/struts 应用程序转换为 AL)时遇到的一件事是 Xcode 为每个视图生成的百万个约束,以及如何清理它们并明智地覆盖一些/全部在代码中。为了一次一个视图进行这种转换,我想要关闭那些自动生成的约束。

Why can't I see this checkbox? I'm using Xcode 4.6.

为什么我看不到这个复选框?我正在使用 Xcode 4.6。

回答by Max MacLeod

That checkbox is available in Interface Builder (IB), but only if you are developing Cocoa projects targeted for OS X. For iOS, it's not available at present. You can only set it programmatically.

该复选框在 Interface Builder (IB) 中可用,但前提是您正在开发针对 OS X 的 Cocoa 项目。对于 iOS,目前不可用。您只能以编程方式设置它。

Auto Layout on iOS from my understanding - and others feel free to pitch in here - is not a full implementation of what is available on OS X.

根据我的理解,iOS 上的自动布局 - 其他人可以在这里随意介绍 - 并不是 OS X 上可用功能的完整实现。

To be honest, given what you say afterwards, this checkbox is probably something you don't need to worry about. I think it is important in upgrading OS X projects to Auto Layout, but generally for iOS it's unlikely you'll be mixing one and the other. I.e., you either checkbox your Xib in the File Inspector to "Use Autolayout" or you don't.

老实说,考虑到您事后所说的话,这个复选框可能是您不需要担心的。我认为将 OS X 项目升级到自动布局很重要,但通常对于 iOS,您不太可能将一个和另一个混合在一起。即,您要么在文件检查器中选中 Xib 以“使用自动布局”,要么不选中。

enter image description here

在此处输入图片说明

That said, there is one use case where you may need to mess with that flag. That's if you want to create a standalone Xib file for a view, and then load that programmatically using loadNibNamed. When doing that, by default old style Auto Resizing constraints are converted into new style Auto Layout constraints. Typically I want to add my own so I set that flag to zap 'em.

也就是说,在一个用例中,您可能需要弄乱该标志。如果您想为视图创建一个独立的 Xib 文件,然后使用loadNibNamed. 这样做时,默认情况下旧样式的自动调整大小约束将转换为新样式的自动布局约束。通常我想添加我自己的,所以我将该标志设置为 zap 'em。

myView.translatesAutoresizingMaskIntoConstraints = NO

myView.translatesAutoresizingMaskIntoConstraints = NO

Anyway that's another story.

反正那是另一个故事了。

Here's the link for more info, although you've no doubt had a look at it already:

这是更多信息的链接,尽管您肯定已经看过它了:

Adopting Auto Layout

采用自动布局

One thing I'd say is that if you're struggling with Auto Layout in the beginning - and you wouldn't be human if you weren't, we all have been - then I'd stick with Interface Builder and think about the golden rules. The most important one for me is that it hates ambiguity. It's like a vacuum in nature. Before you can delete the constraint that you don't want, you have to add the one that you do wantthen zap the old one.

我要说的一件事是,如果您一开始就为自动布局而苦苦挣扎 - 如果不是,您就不会成为人类,我们都曾经如此 - 那么我会坚持使用 Interface Builder 并考虑黄金法则。对我来说最重要的是它讨厌模棱两可。这就像自然界中的真空。在删除约束,你不想要,你必须添加一个,你想,然后将清除旧的。

The other mistake that I made was mixing Auto Layout and frames. So I'd do some code that checked the frame width then apply that to the constraints. Bad mistake. That really ends in tears. When you get into Auto Layout it's essential to really forget about doing anything with CGRect, frame, etc.

我犯的另一个错误是混合了自动布局和框架。所以我会做一些检查框架宽度的代码,然后将其应用于约束。糟糕的错误。这真的是泪流满面。当你进入自动布局它真的忘记带做任何事情非常必要CGRectframe等等。

Stick with it though. Start with some simple views in IB and experiment. There is method to the madness, really.

坚持下去。从 IB 中的一些简单视图开始并进行实验。有办法的疯狂,真的。

One more link also worth looking at is:

另一个值得一看的链接是:

10 Things You Need To Know About Cocoa Autolayout

关于 Cocoa 自动布局你需要知道的 10 件事