[英]how to set a different constraint for different size classes
I want a view to have width 0.4 screen width in landscape and 0.5 screen width in portrait. 我希望视图的横向宽度为0.4,屏幕宽度为0.5。
So I have tried "vary for traits". 所以我尝试过“因性状而异”。 I selected wC hR and set 0.5 and clicked "done".
我选择了wC hR并设置了0.5并点击了“完成”。 Then I selected wR hR and set 0.4 as shown:
然后我选择了wR hR并设置为0.4,如下所示:
Yet both size classes still show as 0.4. 然而,两个尺寸等级仍显示为0.4。
I have also tried setting the constraints using "view as ...(wC hR) etc. without using vary for constraints. 我也尝试使用“视图为...(wC hR)等设置约束,而不使用约束变化。
I have also tried adding a separate size class in the box shown, but with no success. 我也尝试在显示的框中添加一个单独的大小类,但没有成功。
Width size class doesn't always change with the orientation - not on every device. 宽度大小类并不总是随方向而改变 - 不是在每个设备上。
For example, only on the Plus devices the landscape becomes Regular width, but on other devices it's always compact. 例如,仅在Plus设备上,横向变为常规宽度,但在其他设备上,它总是紧凑的。
However, the height size class changes on any iPhones (not iPads): 但是,任何iPhone(而不是iPad)上的高度尺寸类都会发生变化:
hR
- for portrait and hR
- 用于肖像和 hC
- for landscape. hC
- 用于景观。 The illustrations on this page should give you more understanding how they work: http://useyourloaf.com/blog/size-classes/ 本页面上的插图可以让您更好地了解它们的工作原理: http : //useyourloaf.com/blog/size-classes/
Since there is no option to change the multiplier for different size classes, you need to create two constraints, and set conditions for Installed
. 由于没有选项可以更改不同大小类的乘数,因此需要创建两个约束,并为
Installed
设置条件。
This one for landscape: 这个景观:
And for portrait: 对于肖像:
In I phones - 2 types size - 在我的手机 - 2种类型 -
1. portrait mode - wC hR Landscape mode - wC hC 2. portrait mode - wC hR Landscape mode - wR hC 1.纵向模式 - wC hR风景模式 - wC hC 2.纵向模式 - wC hR风景模式 - wR hC
Steps 1.- Select 6s device portrait mode in scene : give the constraint 0.5 screen width. 步骤1.-在场景中选择6s设备纵向模式:给出约0.5屏幕宽度。 elect 6s device landscape mode in scene[just click landscape orientation] : go to vary for traits select both width and height.
在场景中选择6s设备横向模式[只需单击横向]:根据特征选择宽度和高度。 Start your work now.
现在就开始工作吧。 Remove the constraint of width.
删除宽度约束。 Add new constraint of width give the constraint 0.4 screen width.
添加新的宽度约束给出约束0.4屏幕宽度。
2.- Select 6s Plus device landscape mode in scene[just click landscape orientation] : go to vary for traits select both width and height. 2.-在场景中选择6s Plus设备横向模式[只需单击横向]:根据特征选择宽度和高度。 Start your work now.
现在就开始工作吧。 Remove the constraint of width.
删除宽度约束。 Add new constraint of width give the constraint 0.4 screen width.
添加新的宽度约束给出约束0.4屏幕宽度。 Now its works perfect in i phone not in i pad because i pad size is different.
现在它的作品完美在我的手机而不是i垫,因为我的垫尺寸不同。 We need to some work in i pad then it works i pad also.
我们需要在i垫上做一些工作然后它也适用于我垫。 Try it.
试试吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.