Xcode 6 自适应 UI 如何向后兼容 iOS 7 和 iOS 6? [英] How can Xcode 6 adaptive UIs be backwards-compatible with iOS 7 and iOS 6?

查看:29
本文介绍了Xcode 6 自适应 UI 如何向后兼容 iOS 7 和 iOS 6?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚观看了 WWDC 视频 #216,使用 UIKit 构建自适应 UI."

I just watched the WWDC video #216, "Building Adaptive UI with UIKit."

在大约 45:10 Tony Ricciardi 谈到了 Xcode 6 中 IB 的变化以支持新的变化.

At about 45:10 Tony Ricciardi talks about changes to IB in Xcode 6 to support the new changes.

他说您可以将这些文档向后部署到旧版本的 iOS".

He says "You can deploy these documents backwards to older versions of iOS".

(其中这些文档"大概是指对不同大小类别具有特定设置的 XIB 和故事板.)

(where "These documents" presumably means XIBs and storyboards that have specific settings for different size classes.)

这不是我编的.去观看 WWDC 视频.

I'm not making this up. Go watch the WWDC video.

这怎么可能?Trait 集合和大小类仅在 iOS 8 中定义.依赖于 iOS 8 新的 UI 构造的运行时行为如何在以前的 iOS 版本中工作?

How is that possible? Trait collections and size classes are only defined in iOS 8. How can runtime behavior that's dependent on UI constructs that are new to iOS 8 work in previous iOS versions?

如果可能,那就太好了.您可以构建可在 iOS 6、7 和 8 上运行的应用程序,并利用 Apple 已添加到 Xcode 6 的新的灵活 UI 布局功能.我自己在代码中创建了自适应 UI 逻辑,而且相当多工作的.

If it is possible it would be wonderful. You could build apps that will run on iOS 6, 7, and 8, and take advantage of the new flexible UI layout abilities that Apple has added to Xcode 6. I've created adaptive UI logic myself in code, and it's quite a bit of work.

推荐答案

在 Interface Builder 中对 UI 大小类所做的更改在 iOS 7 设备和 Xcode 预览中正确显示.例如,我为常规高度常规宽度更改了一些自动布局约束和字体大小,这些更改的约束在运行 iOS 7.0 的 iPad 模拟器中可见.

Changes made to the UI with Size Classes in Interface Builder DO appear correctly on iOS 7 devices and the Preview in Xcode. For example, I changed some Auto Layout constraints and font sizes for Regular height Regular width and those changed constraints are visible in the iPad Simulator running iOS 7.0.

所有尺寸类优化都可用于 iOS 7,但具有 Compact Height 的尺寸类除外.这已被 Apple 确认,现在直接在 文档:

All size class optimizations are made available to iOS 7, except size classes that have a Compact Height. This has been confirmed by Apple and is now stated directly in the documentation:

对于支持早于 iOS 8 的 iOS 版本的应用,大多数大小类都向后兼容.

在以下情况下,尺寸类向后兼容:
- 该应用程序是使用 Xcode 6 或更高版本构建的
- 应用部署目标早于iOS 8
- 大小类在故事板或 xib
中指定- 高度组件的值不紧凑

因为 iOS 7 不尊重几个大小类,如果你使用它们,你会遇到问题.例如:当您定义 Compact w Any h 并定义 Compact w Compact h 时,在 iOS 7 上它将尊重 Compact w Any h,但在 iOS 8 上它呈现 Compact w Compact h 外观.

Because iOS 7 doesn't respect a couple of size classes, if you use them you'll run into issues. For example: When you have Compact w Any h defined and then Compact w Compact h defined, on iOS 7 it will respect the Compact w Any h but on iOS 8 it renders the Compact w Compact h appearance.

因此,如果您想利用这两个尺寸类并保持与 iOS 7 的兼容性,我会在 Any w Any h 或 Compact w Any h 中为横向的 iPhone 进行您想要的任何优化,然后执行您的其他优化根据需要使用不同的尺寸等级,这样您就不需要使用任何高度紧凑的尺寸等级,并避免遇到问题.

So, if you would like to utilize those two size classes and maintain compatibility with iOS 7, I would do any optimizations you desire for iPhone in landscape in Any w Any h or Compact w Any h, then perform your other optimizations for different size classes as necessary, and that way you won't need to use any size class with compact height and will avoid running into issues.

这篇关于Xcode 6 自适应 UI 如何向后兼容 iOS 7 和 iOS 6?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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