了解 IOS8 大小类 [英] Understanding IOS8 size classes

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

问题描述

我一直在 Xcode 上使用大小类来尝试理解它.我遇到的问题是,许多不同尺寸的手机都适合相同的尺寸等级(就像所有 iPhone 纵向版一样),因此我无法在 3.5 英寸屏幕上使用.这令人沮丧,因为我想更改手机之间的布局约束,而不仅仅是类,因为显然我需要使事物之间的间隙更大或按钮稍大以保持一切成比例.我不知道这是不是我遗漏的东西,但似乎我能做到这一点的唯一方法是创建每个我想要更改为插座的布局约束,然后测试每部手机的代码并使用粗略的更新它在模拟器上估计并运行这个东西.

I have been playing around on Xcode with size classes to try and make sense of it. The problem I have is that many different sized phones all fit into the same size class (like all iPhones in portrait) so I can't home in on a 3.5 inch screen for example. This is frustrating as I would like to change the layout constraints between phones rather than just classes as obviously I need to make the gaps between things larger or the buttons slightly bigger to keep everything in proportion. I don't know if it is something I have missed but it seems the only way I can do this is by creating every single layout constraint I want to change as an outlet and then testing in code for each phone and updating it using a rough estimate and run the thing on the simulator.

总而言之,当它们都在同一个类中时,如何根据设备的大小调整约束?使用百分比/比例约束应该可以得到我想要的结果.

In Summary, how can I adjust the constraints based on the size of a device, when they're all in the same class? Using a percentage/proportional constraint should give me the result I'm after.

推荐答案

Apple 的设计让您无需考虑特定设备.这个想法是您使用自动布局,以便每个屏幕自动调整到可用空间.Size classes 是它的扩展,因此当您获得大量额外空间时,您可以做一些稍微不同的事情.

Apple have designed it so that you don't have to think about specific devices. The idea is that you use auto layout so that each screen automatically adjusts to the available space. Size classes is an extension of that so when you get a lot of extra space you can do something slightly different.

如果您想针对特定设备自定义布局,您可以.和你描述的差不多.然而,当 Apple 明年发布 iPad Pro 和 4.3" iPod touch 时会发生什么(你首先在这里阅读了它)?通常,不需要硬编码间距和大小;你的界面应该缩放以使用可用空间,这就是自动布局和大小类为您提供的.

If you want to customise your layout to specific devices, you can. Pretty much as you describe it. However, what happens next year when Apple release the iPad Pro and a 4.3" iPod touch (you read about it here first)? In general, there is no need to hard code spacing and sizes; your interface should scale to use the space available, and that's what auto layout and size classes give you.

将其视为约束条件而不是已知屏幕尺寸列表当然更难,但这应该是值得的.

It's certainly harder to think it terms of constraints rather than a list of known screen sizes, but it should be worth it.

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

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