iOS自动版面配置与Springs&撑杆 [英] iOS Auto Layout vs Springs & Struts

查看:57
本文介绍了iOS自动版面配置与Springs&撑杆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一年前,我见过关于WWDC自动布局的好处的几个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&仅适用于iOS 7应用程序的Struts,是否避免使用自动布局"?还是我这样做会输掉任何东西?在不同情况下使用自动布局的学习和掌握技能可能需要花几天的时间,因此,我非常感谢一些有争议的建议.

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不会遇到太多麻烦,自动布局功能强大.

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中的框架与使用布局约束框架计算出的框架实际不同时,Interface Builder将用红色虚线指示该元素的运行时框架.最后,它做对了.谢谢,苹果.

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中利用所有这些.您需要Apple开发者帐户才能查看.

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.

推荐答案

自动布局"是未来,而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上还处于初期,尽管我不确定确切含义是什么,但

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中,自动版式可以帮助应用适应新的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&支撑或使用框架手动计算指标.

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自动版面配置与Springs&撑杆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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