iOS 自动布局 vs Springs &支柱 [英] iOS Auto Layout vs Springs & Struts

查看:15
本文介绍了iOS 自动布局 vs Springs &支柱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一年前,我在 Apple WWDC 上看到了几个关于自动布局好处的主题演讲,但是当我在现实世界的项目中尝试它们时,我体验到当你在 Storyboard 上稍微移动一些 UI 元素时,它会破坏一半约束,抵消了自动布局的所有好处.

A year ago I've seen couple of Apple WWDC keynotes about benefits of Auto Layout, but when I tried them in real world projects, I experienced that when you move some UI element on a Storyboard even slightly, it breaks half of the constraints, nullifying all the benefits of Auto Layout.

直到现在我一直在使用 Springs &Struts 非常成功,结合 KVO 观察 frame 视图路径,优雅地处理了大部分旋转重新对齐,只需几行代码.

Till now I've been utilising Springs & Struts quite successfully, and in conjunction with KVO observing frame path for view, handled most of rotation realignments gracefully, with just couple lines of code.

现在随着 iOS 7 的推出,我有一个问题:我能否继续成功地使用 Springs &Struts 仅适用于 iOS 7 应用程序并避免使用自动布局?还是我这样做会失去什么?学习和掌握在不同场景中使用自动布局的技巧对我来说可能需要几天时间,所以我非常感谢一些有争议的建议.

So now with iOS 7 coming out, I got a question: Can I keep successfully utilising Springs & Struts only for iOS 7 apps and avoid using Auto Layout? Or am I losing out on anything by doing so? Learning and mastering skill of using Auto Layout in different scenarios would probably take couple of days to me, so I'd really appreciate some argumented advice.

已解决:感谢 Max 的回答,我开始深入研究自动布局;而 Null 在他的回答中是正确的 - 你实际上可以使用 Springs &iOS 7 上的 Struts 没有太多麻烦,Auto-Layout 很强大.

RESOLVED: Thanks to Max's answer, I started to dig into Auto Layout; while Null is right in his answer - you actually can use Springs & Struts on iOS 7 without too much trouble, Auto-Layout is powerful.

显然在 Xcode 5 中,修复了以下内容:

Apparently in Xcode 5, the following things are fixed:

  • 要删除约束,您实际上并不需要执行古老的萨满教雨之舞.你删除它,布局进入警告模式,表明你需要解决的问题才能使自动布局工作.

  • To delete a constraint you don't actually need to perform ancient shamanic dance of rain. You delete it and layout goes into warning mode, indicating issues you need to resolve to make Auto Layout work.

当你移动东西时,你的约束不会改变;仅在 Interface Builder 中的视图框架发生变化.

When you move things around, your constraints does not change; only view frame in Interface Builder changes.

当Interface Builder中的frame实际上与用布局约束计算的frame不同时,Interface Builder会用红色虚线表示该元素的运行时frame.最后它做对了.谢谢,苹果.

When frame in Interface Builder is actually different from calculated with layout constraints frame, Interface Builder will indicate the runtime frame of that element with red dotted line. Finally it is done right. Thanks, Apple.

这是 WWDC 2013 会议的链接,演示了如何在 Xcode 5 中使用所有这些.您需要苹果开发者帐户才能查看.

Here's a link to WWDC 2013 session that demonstrates how to utilise all of that in Xcode 5. You'd need apple developer account to view that.

所以我现在的选择是自动布局.谢谢大家.

So my choice now is Auto Layout. Thank you everybody.

推荐答案

Auto Layout is the future and Springs &Struts 是过去式了.如果您继续使用 Springs &随着新标准 - 自动布局 - 变得流行,Struts 你将处于劣势.

Auto Layout is the future and Springs & Struts is the past. If you continue to use Springs & Struts you will be at a disadvantage as the new standard - Auto Layout - becomes prevalent.

此外,Springs &Struts 对复杂视图无效.自动布局功能要强大得多.

Also, Springs & Struts isn't effective for complex views. Auto Layout is considerably more powerful.

对于 iOS 7,现在还为时尚早,虽然我不确定这到底意味着什么, iOS 7 UI 过渡指南 特别提到使用自动布局将简化过渡过程:

With iOS 7, it's early days, and although I'm not sure exactly what the implications are, the iOS 7 UI Transition Guide specifically mentions that using Auto Layout will ease the transition process:

如果您的应用使用自动布局,您的工作会更轻松.在 Xcode 5 中,Auto Layout 可以帮助应用程序适应新的 UI 元素指标并适当响应文本大小的动态变化.如果您要转换 iOS 6 应用或需要同时支持 iOS 6 和 iOS 7,则自动布局特别有用.

If your app uses Auto Layout, your job is easier. In Xcode 5, Auto Layout can help an app accommodate new UI element metrics and respond appropriately to dynamic changes in text size. Auto Layout is particularly helpful if you’re transitioning an iOS 6 app or you need to support both iOS 6 and iOS 7.

如果您没有使用自动布局,现在可能是开始的最佳时机,特别是如果您需要支持多个版本的应用程序.如果您使用手动或程序化布局技术,您有责任确保在文本大小时适当调整布局变化.

If you didn’t use Auto Layout, now may be the perfect time to start, especially if you need to support more than one version of an app. If you use manual or programmatic layout techniques, you're responsible for ensuring that the layout adjusts appropriately when text size changes.

就我个人而言,我从 Xcode 4.6.3 开始使用自动布局.最初的学习曲线是痛苦的,但之后它真的变得使用起来很愉快.我绝对不会回到 Springs &Struts 或使用框架手动计算指标.

Personally, I've been using Auto Layout since Xcode 4.6.3. The initial learning curve is painful, but after that it really becomes a joy to use. I'd definitely never go back to Springs & Struts or manually calculating metrics using frames.

这篇关于iOS 自动布局 vs Springs &支柱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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