在iOS 6中启用自动布局,同时保持向后兼容的iOS 5兼容 [英] Enabling auto layout in iOS 6 while remaining backwards compatible with iOS 5

查看:411
本文介绍了在iOS 6中启用自动布局,同时保持向后兼容的iOS 5兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是采取的iOS 6的新的自动排版功能优势,同时还在早期版本的iOS提供与保持兼容旧设备的最佳方式?

What is the best way to take advantage of the new auto layout features of iOS 6 while still providing compability with older devices on earlier versions of iOS?

推荐答案

自动布局可以启用或每个.storyboard或文件的.xib禁用。只需选择特定的文件和使用文件检查以x code修改使用自动布局属性:

Autolayout can be enabled or disabled on each .storyboard or .xib file. Just select the particular file and modify the "Use Autolayout" property using the File inspector in Xcode:

在编译错误使用自动布局启用接口文件设置为一个IOS版本的部署目标6.0之前的结果,例如:

Using autolayout enabled interface files with the deployment target set to an iOS version prior to 6.0 results in compilation errors, e.g.:

错误MainStoryboard.storyboard:3:自动布局在iOS 6.0以前的版本

Error in MainStoryboard.storyboard:3: Auto Layout on iOS Versions prior to 6.0

你的一个选项在项目中使用自动版式,仍然美元,iOS4-5 p $ pserve兼容性是创建两个<一个href=\"https://developer.apple.com/library/ios/#featuredarticles/X$c$cConcepts/Concept-Targets.html\">targets:一个用于部署目标的iOS 6.0,一个为早期版本的iOS,例如:

One of your options to use autolayout in a project and still preserve compatibility with iOS4-5 is to create two targets: one for deployment target iOS 6.0 and one for an earlier iOS version, e.g.:

您可以为每个故事板和XIB文件的创建两个版本,以及并使用与6.0的目标和其他与传统目标,例如启用了自动布局:

You can create two versions for each of your storyboard and XIB files as well and use the autolayout enabled with the 6.0 target and the other with the legacy target, e.g.:

您再添加MainStoryBoardAut​​oSize到iOS6的目标构建阶段和其他文件到iOS4的目标。您可以了解更多有关使用多个目标这里

You then add MainStoryBoardAutoSize to the iOS6 target's Build phases and the other file to the iOS4 target. You can learn more about using multiple targets here.

编辑: marchinram的回答指出,如果从code加载你的故事板文件,也不要使用在X code中的主故事板的设置来设置初始故事板,你可以使用一个单一的目标。

As marchinram's answer points out, if you load you storyboard files from code and do not use the "Main Storyboard" setting in Xcode to set the initial storyboard, you can use a single target.

对于我来说,保持多个目标和接口文件的复杂性增加的成本似乎超过使用自动布局的好处。除少数特殊情况下,你可能最好使用普通的旧式自动调整大小(或code layoutSubViews)独家如果需要iOS4-5兼容性。

For me, the cost of the added complexity of maintaining multiple targets and interface files seems to outweigh the benefits of using autolayout. Except for a few special cases, you are probably much better to use plain old auto sizing (or layoutSubViews from code) exclusively if iOS4-5 compatibility is required.

这篇关于在iOS 6中启用自动布局,同时保持向后兼容的iOS 5兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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