UITraitCollection澄清 [英] UITraitCollection Clarification

查看:127
本文介绍了UITraitCollection澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图弄清楚如何以编程方式使用 UITraitCollection ,但我发现很难理解它。我正在iOS 8中开发iPad视网膜。

I'm trying to figure out how to use UITraitCollection programatically, but I find it difficult to make sense of it. I'm developing for an iPad retina, in iOS 8.

println(self.traitCollection)返回以下内容输出:

 <UITraitCollection: 0x10df4c7f0; _UITraitNameUserInterfaceIdiom = Pad,
 _UITraitNameDisplayScale = 2.000000, _UITraitNameHorizontalSizeClass = Regular, 
 _UITraitNameVerticalSizeClass = Regular, _UITraitNameTouchLevel = 0, 
 _UITraitNameInteractionModel = 1>

这很简单。
但是当我旋转屏幕时,我得到完全相同的输出。即,相同的垂直尺寸类和相同的水平尺寸类。

Which is pretty straight forward. But when I then rotate the screen, I get the exact same output. I.e., same vertical size class, and same horizontal size class.

所以我的问题是,我是否需要为每个设备方向指定我想要的尺寸类(目前为止)正如我所看到的,大小类是只读属性!)或者我错过了一些明显的东西?
在WWDC 2014视频网站上的Cocoa-Touch中的新内容演讲中给出的示例中,他使用iPhone作为示例,每个设备方向都有不同的垂直/水平尺寸类。

So my question is, do I need to specify the size class I want for each device orientation (as far as I can see, the size classes are read-only properties!) or am I missing something obvious? In the example given in the 'What's new in Cocoa-Touch' talk on the WWDC 2014 video site, he uses the iPhone as an example, which has different vertical / horizontal size classes for each device orientation.

你会怎么做?

推荐答案

此文档(滚动到 Universal Storyboard for Universal Apps )解释了iPad和iPhone的尺寸等级。

This document (scroll to Unified Storyboards for Universal Apps) explains the size classes for both iPads and iPhones.

请注意,iPhone有点棘手。所有iPad在任何方向都是Regular-x-Regular,但iPhone的尺寸等级会改变方向,从Portrait中的Regular(h)-x-Compact(w)到Landscape中的Compact-x-Compact。

Note that the iPhone is a bit tricky. All iPads are Regular-x-Regular in any orientation, but an iPhone's size classes change on orientation, from Regular(h)-x-Compact(w) in Portrait, to Compact-x-Compact in Landscape.

所有这些变化的谣言说明苹果可能会很快推出更多的屏幕分辨率,目前的数字已经需要一堆if-then而没有这些尺寸等级。为了简化这种转变,我建议您考虑更像响应式网页设计的内容,在这里您可以定义一些通用布局,然后在其中一个布局中以任何精确的尺寸进行拉伸以适应。

The rumored explanation for all these changes is that Apple might be introducing more screen resolutions soon, and the current number already requires a bunch of if-then's without these size classes. To ease this transition, I'd recommend thinking about things more like responsive web design, where you define a few general layouts, then stretch things to fit nicely at any exact size within one of those layouts.

编辑:

1)如果链接断开,找到iOS中的新东西Apple Doc,转到iOS8部分,寻找支持新的屏幕大小和尺度

1) In case the link breaks, find the "Whats New in iOS" Apple Doc, go to the iOS8 section, and look for "Supporting New Screen Sizes and Scales"

2)iPhone 6+在横向模式下具有常规宽度。

2) The iPhone 6+ has a regular width in landscape mode.

这篇关于UITraitCollection澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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