简体   繁体   English

如何使用尺寸等级为小型iPhone和iPhone 6加上不同的设计?

[英]How to make a different design for small iPhones and iPhone 6 plus using size classes?

Is is possible to make a different design in Interface Builder for iPhone 6 plus and other iPhones using size classes? 是否可以在Interface Builder for iPhone 6 plus和其他使用大小类的iPhone中进行不同的设计? I need only portrait mode. 我只需要肖像模式。

According to some tutorials ( http://swiftiostutorials.com/using-size-classes-xcode-6/ ) it seems that it should be possible. 根据一些教程( http://swiftiostutorials.com/using-size-classes-xcode-6/ ),它似乎应该是可能的。 Also in IB Compact+Any seems to be for small iPhones: 同样在IB Compact + Any似乎适用于小型iPhone:

在此输入图像描述

and Compact+Regular for all iPhones: 适用于所有iPhone的Compact + Regular:

在此输入图像描述

But when I am trying to receive a different design it not works. 但是,当我试图接受不同的设计时,它不起作用。 For example how to hide a view for small iPhones and show it for iPhone 6 plus? 例如,如何隐藏小型iPhone的视图并将其显示为iPhone 6 plus? 在此输入图像描述

Sadly you can only do that for landscape (where the iPhone 6 plus has a different trait collection than the rest of the iPhone family). 可悲的是,你只能用于横向(iPhone 6 plus具有与其他iPhone系列不同的特征集合)。

The way it is worded in IB is kind of misleading. 它在IB中的措辞方式有点误导。 You are right in expecting the w Compact h Regular to overwrite the rule for w Compact h Any. 你是正确的期望w Compact h Regular来覆盖w Compact h Any的规则。 The problem is that the iPhone 6 plus falls under the w Compact h Regular category too. 问题是,在iPhone 6下加在WH普通类下降太多。

Printing a view's trait collection when running on an iPhone 6 plus proves this: 在iPhone 6 plus上运行时打印视图的特征集证明了这一点:

<UITraitCollection: 0x7f968ada42c0; _UITraitNameUserInterfaceIdiom = Phone, _UITraitNameDisplayScale = 3.000000, _UITraitNameHorizontalSizeClass = Compact, _UITraitNameVerticalSizeClass = Regular, _UITraitNameTouchLevel = 0, _UITraitNameInteractionModel = 1>

These two in particular: 这两个特别是:

_UITraitNameHorizontalSizeClass = Compact, _UITraitNameVerticalSizeClass = Regular

You can change/override the traits at runtime (ie tell a view "no matter what you think, I say you have a Compact height etc") but for your case I would just switch on the screen's height and hide views manually based on that information. 您可以在运行时更改/覆盖特征(即告诉视图“无论您的想法如何,我说您有紧凑的高度等”)但是对于您的情况,我只需打开屏幕的高度并基于此手动隐藏视图信息。

In portrait orientation, you cannot use size classes to distinguish between the iPhone 6 and 6+. 在纵向方向上,您无法使用尺寸类来区分iPhone 6和6+。 You will have to do this programmatically by checking the screen height after your view loads. 您必须通过在加载视图后检查屏幕高度以编程方式执行此操作。

The Human Interface Guidelines show that both phones have the same trait collection in portrait: Compact width/Regular height . 人机界面指南显示,两部手机都具有相同的纵向特征: 紧凑宽度/常规高度 The collection in your first image is Compact width/Any height, which includes Compact width/Regular height- that's why you're not seeing a difference if you install a view in one but not the other. 第一张图片中的集合是紧凑宽度/任何高度,其中包括紧凑宽度/常规高度 - 这就是为什么如果您在一个视图而不是另一个视图中安装视图时没有看到差异的原因。

While not applicable to your case, it is worth noting that you can distinguish between the two devices in landscape orientation, as the 6+ uses Regular width/Compact height, but smaller phones use Compact width/Compact height. 虽然不适用于您的情况,但值得注意的是,您可以在横向方向上区分这两个设备,因为6+使用常规宽度/紧凑高度,但较小的手机使用紧凑宽度/紧凑高度。

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

相关问题 如何创建一个适用于iPhone 4至iPhone 6 Plus的XIB,而无需使用尺寸类和情节提要? - How to create a XIB that works from iPhone 4 to iPhone 6 Plus without using size classes and storyboards? 大小类来区分iPhone 5,6和6 Plus? - Size Classes to distinguish between iPhone 5, 6 and 6 Plus? iPhone 6加上横向模拟器尺寸大小 - iPhone 6 plus simulator size classes in landscape iPhone 6 Plus及更高版本的Xcode约束和大小类 - Xcode constraint and size classes for iphone 6 plus and up 如何在不同的iPhone中更改uilabel文本大小 - how to change uilabel text size in different iPhones 如何同时模拟不同尺寸的iPhone? - How to simulate different size iPhones in the same time? iPhone SE中的ios设计,但我想在iPhone 8 Plus中进行设计 - ios design in iphone SE but I want to make the design in iphone 8 plus 如何在Xcode中的不同iPhone尺寸类中使用不同尺寸的图像 - How to use different size of image in different iPhone size classes in Xcode 非横向尺寸的iPhone(例如iPhone 5、6、8等)是否可以在横向模式下使用拆分视图(UISplitViewController)? - Is split view (UISplitViewController) possible in landscape mode for non plus size IPhones like IPhone 5, 6, 8 etc.? 如何使用尺寸类使应用程序兼容iphone 5,iphone 6,iphone 6 plus - How to use size class to make app compatible to iphone 5, iphone 6, iphone 6 plus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM