简体   繁体   中英

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.

So I have tried "vary for traits". I selected wC hR and set 0.5 and clicked "done". Then I selected wR hR and set 0.4 as shown:

约束的设置

Yet both size classes still show as 0.4.

I have also tried setting the constraints using "view as ...(wC hR) etc. without using vary for constraints.

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.

However, the height size class changes on any iPhones (not iPads):

  • hR - for portrait and
  • hC - for landscape.

The illustrations on this page should give you more understanding how they work: 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 .

在此输入图像描述

This one for landscape:

在此输入图像描述

And for portrait:

在此输入图像描述

In I phones - 2 types size -
1. portrait mode - wC hR Landscape mode - wC hC 2. portrait mode - wC hR Landscape mode - wR hC

Steps 1.- Select 6s device portrait mode in scene : give the constraint 0.5 screen width. elect 6s device landscape mode in scene[just click landscape orientation] : go to vary for traits select both width and height. Start your work now. Remove the constraint of width. Add new constraint of width give the constraint 0.4 screen width.

2.- Select 6s Plus device landscape mode in scene[just click landscape orientation] : go to vary for traits select both width and height. Start your work now. Remove the constraint of width. Add new constraint of width give the constraint 0.4 screen width. Now its works perfect in i phone not in i pad because i pad size is different. We need to some work in i pad then it works i pad also. Try it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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