简体   繁体   English

Xcode 6大小类

[英]Xcode 6 Size Classes

I would like to ask a question about the highly confusing (at least to me) topic - Size Classes in Xcode 6. I have been trying to get a full understanding of how all this works, but it is still not clear to me. 我想问一个有关高度混乱(至少对我来说)的问题-Xcode 6中的大小类。我一直在试图全面了解所有这些工作原理,但是我仍然不清楚。

Before Xcode 6 and the new iPhones, everything was very straightforward. 在Xcode 6和新iPhone之前,一切都非常简单。 To, Non-Retina and Retina, displays that enabled us to work with always same resolution 320x480 (or 568 for taller devices). To(非视网膜和视网膜)显示使我们能够始终以相同的分辨率320x480(对于更高的设备为568)工作。 Standard and @2x assets made perfect sense. 标准和@ 2x资产非常合理。 Now however, we have the big ass screens with the same ratio (almost the same), but working area is not the same any more. 但是现在,我们的大屏幕的屏幕具有相同的比率(几乎相同),但是工作区域不再​​相同。

Size Classes are supposed to make things possible to fit all of it in one storyboard. 大小类应该使所有内容适合一个故事板。 But wait.. iPhone 6 uses @2x assets, which, in my understanding, means that the graphics will look smaller on that device than on iPhone 5/5S. 但是,等等。iPhone 6使用@ 2x资产,据我了解,这意味着该设备上的图形看起来比iPhone 5 / 5S上的小。 And iPhone 6 Plus uses @3x assets, which again aren't gonna look the same. iPhone 6 Plus使用@ 3x资产,看起来也不一样。 Seems like it is not possible to make, for example, a certain button always be of the same size in relation to, say, full width of the screen. 似乎无法使某个按钮相对于屏幕的整个宽度始终具有相同的大小。 Unless we code that of course, but that would make Size Classes useless. 除非我们当然进行编码,否则这将导致Size类无用。

Am I understanding things correctly or am I missing something? 我是正确理解事物还是错过了某些事物? It would be great to hear how you all see it. 很高兴听到大家的看法。 Maybe you know some good tutorials? 也许您知道一些不错的教程? I haven't found anything that would explain my doubts. 我还没有发现任何可以解释我怀疑的东西。

Thanks in advance! 提前致谢!

You can do much of what you're talking about here using a combination of different approaches: 您可以使用多种不同方法的组合来完成此处所说的大部分事情:

  1. Size classes for different types of devices to cover most large-scale changes in UI configuration (for example, differences between iPad and iPhone). 不同类型设备的大小类,以涵盖UI配置中的大多数大规模更改(例如,iPad和iPhone之间的差异)。 You might use this to change whether a sidebar appears or not, for example. 例如,您可以使用它来更改是否显示侧边栏。

  2. Autolayout rules that are specific to individual size classes. 特定于单个尺寸类别的自动布局规则。 You might add different autolayout rules for different size classes in order to tweak the layout (for example, you might switch between a horizontal row of buttons and a stacked column of buttons this way, since you can now have different Autolayout rules for different size classes). 您可以为不同的尺寸类别添加不同的自动布局规则,以调整布局(例如,您可以通过这种方式在水平按钮行和堆叠的按钮列之间进行切换,因为您现在可以为不同尺寸类别使用不同的自动布局规则)。 This technique is extremely powerful once you realize that you don't need to use the same autolayout rules for all size classes anymore. 一旦您意识到不再需要对所有尺寸类别使用相同的自动布局规则,此技术将非常强大。

  3. Asset catalogs to switch out pre-rendered graphics for the different supported resolutions, etc, automatically. 资产目录可自动为不同的支持分辨率等切换出预渲染的图形。 Note also that because many older devices don't actually support iOS 8, you don't need to include the really low-res versions anymore unless you need extensive backwards compatibility (and if you do, not all of the size class features are available anyway). 另请注意,由于许多较旧的设备实际上并不支持iOS 8,因此您不再需要包含真正的低分辨率版本,除非您需要广泛的向后兼容性(如果这样做,则并非所有size类功能都可用)无论如何)。 I just made a new version of the app that only supports iOS 8, since users on older versions will just get the previous version of the app. 我刚刚制作了仅支持iOS 8的应用程序的新版本,因为使用旧版本的用户将仅获得该应用程序的先前版本。

  4. Resizable images: you can now specify resizable areas within images in order to control how they get stretched when applied to things like UIButtons, etc, that may change size according to Autolayout rules. 可调整大小的图像:您现在可以在图像中指定可调整大小的区域,以控制将其应用于UIButton等物体时如何拉伸它们,这些东西可能会根据自动版式规则更改大小。 (This is a feature Android has had for quite a while, so it's welcome on iOS.) This means that you can make things look good on a wider variety of screen sizes without having as many separate images or as much precise control over the size of the UI elements. (这是Android已有一段时间的功能,因此在iOS上很受欢迎。)这意味着您可以在各种屏幕尺寸上使外观看起来不错,而无需拥有太多单独的图像或对尺寸进行精确控制UI元素。

  5. Programmatic code in the view controllers to tweak anything that you can't achieve any other way. 视图控制器中的程序代码可以调整您无法通过其他任何方式实现的功能。

While it's true that you don't have quite as fined grained control over which devices show what exact layout with size classes, I found that this wasn't really as big a problem as you might think, as the size classes let your view controllers adapt to different devices very seamlessly. 的确,您并没有对哪些设备显示具有尺寸级别的确切布局的精细控制,但我发现这并不是您想象的那么大的问题,因为尺寸级别让您的视图控制器非常无缝地适应不同的设备。 The combination of autolayout and size classes is particularly powerful. 自动布局和大小类的组合特别强大。 And it's actually potentially a good thing, because it means less new manual configuration whenever Apple comes out with a different screen size. 实际上,这可能是一件好事,因为每当Apple推出不同尺寸的屏幕时,这意味着较少的新手动配置。 It's a bit of a pain right now to convert, but probably worth it in the long run. 现在进行转换有点痛苦,但从长远来看可能值得。 You just have to think about how you set things up a little bit differently. 您只需要考虑如何将事情设置得有些不同。 It is a little bit more like Android, where they have long had to contend with lots of different device screen sizes and resolutions, but it's also the sort of natural evolution of the platform where you can't really precisely design for every single physical device as a practical matter (you should still test on them in the simulator, though). 它有点像Android,因为他们长期以来一直在面对许多不同的设备屏幕尺寸和分辨率,但这也是该平台的一种自然演进,您无法真正为每个物理设备进行精确设计作为实际问题(尽管您仍然应该在模拟器中对其进行测试)。

Size classes are not there to just adapt to a larger screen size, they are there for completely different layouts. 尺寸类别不仅仅可以适应更大的屏幕尺寸,它们还可以用于完全不同的布局。 Like on an iPhone you might show one item and tap to get to the next screen for more information, but on an iPad you show both on the same screen. 像在iPhone上一样,您可能会显示一个项目,然后点按以进入下一个屏幕以获取更多信息,但在iPad上,您会在同一屏幕上同时显示两者。

For small adjustments, you use auto layout, with different layouts per size class, and the different screen sizes in each size class are handled by the auto layout. 对于较小的调整,可以使用自动布局,每个尺寸类别使用不同的布局,并且每个尺寸类别中的不同屏幕尺寸由自动布局处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM