哪里是在X code&复选框QUOT;转换面膜自动调整大小的约束成" [英] Where is the Xcode checkbox "Translates Autoresizing Mask Into Constraints"

查看:209
本文介绍了哪里是在X code&复选框QUOT;转换面膜自动调整大小的约束成"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的WWDC 2012的视频之一,自动布局实例,他们演示使用自动布局的OS X应用程序,并在大约7或8分钟,他展示了如何为一个单一视图,您可以取消选中属性的盒子督察和箱被称为像翻译面膜自动调整大小约束成。现在,我很清楚code相当于此框,在 translatesAutoresizingMaskIntoConstraints 布尔的,但我似乎无法在任何iOS或OS X项目的地方找到此复选框。我的项目使用自动布局。我真的想此复选框,因为事情我在学习的自动布局奋力一(和转换弹簧/支柱应用AL)是制约百万X code已经为每个视图生成的,以及如何清除它们并理智地覆盖某些/所有code。我想为了在时间做这种转换一种观点是关闭那些自动生成的约束。

为什么我看不到此复选框?我用X code 4.6。


解决方案

这复选框可在Interface Builder(IB),但只有当你正在开发针对OS X.对于iOS可可项目,它不是可在present。您只能设置编程。

自动布局在iOS上使用我的理解 - 和其他人随意在这里球场 - 不是全面实施什么是可在OS X

说实话,因为你说的话之后,此复选框可能是一些你并不需要担心。我认为这是在升级OS X项目自动布局很重要,但一般适用于iOS它不太可能你会被混合一种和其他。即,你要么你复选框厦门国际银行在文件检查器使用自动布局还是你不知道。

这是说,有一个用例,你可能需要惹的标志。那是,如果你想创建一个视图独立XIB文件,然后加载编程方式使用 loadNibNamed 。如果这样做,默认情况下旧式自动调整大小的限制被转换为新的样式自动布局约束。通常情况下我想补充我自己,所以我设置该标志扎普他们。

myView.translatesAutoresizingMaskIntoConstraints = NO

反正是另一回事。

下面的链接了解更多信息,虽然你已经毫无疑问了一下它已经:

<一个href=\"https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AdoptingAutoLayout/AdoptingAutoLayout.html\">Adopting自动布局

有一件事我想说的是,如果你使用自动布局在开始挣扎 - 你不会是人类的,如果你没有,大家都已经 - 那么我会用Interface Builder中,坚持想想金科玉律。对我来说,最重要的是,它不喜欢模棱两可。这就像自然界中的真空。在可以删除该约束的你不想的,你必须增加一个的,你希望的再扎普旧的。

这是我做了混合自动布局和框架的另一个错误。所以,我会做一些code,它检查了边框宽度然后应用的制约。糟糕的错误。这确实在流泪结束。当你进入自动布局这真的忘记带的CGRect 做任何事情帧

虽然坚持下去。开始与IB和试验一些简单的看法。有方法的疯狂,真的。

还有一个链接,也值得一读的是:

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

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 translatesAutoresizingMaskIntoConstraints boolean, 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.

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

解决方案

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.

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.

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.

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.

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 want then zap the old one.

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.

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

One more link also worth looking at is:

10 Things You Need To Know About Cocoa Autolayout

这篇关于哪里是在X code&复选框QUOT;转换面膜自动调整大小的约束成&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆