Constraints depending or Portrait / Landscape

I would need to have constraints that depend on the orientation of the device. Some in Portrait, another in Landscape.


I thought I got it with variations, using hC / hR or wC / wR cominations to detect the orientation.


Nearly worked, as for iPhones, when landscape we have hC and when portrait we have wC.

But that's not the case for iPhone 11 Pro for instance. In landscape, width is Compact, not regular.


I end up with a mess of constraints.


So, I would need to express those constraints depending on orientation and not width Compact or regular.

I looked at traits variations, but I could not bget it this way. It seems to me it is only a way to use wC, wR …, not to express orientation.


I can do it programmatically:

- define IBOutlets for those constraints

- in viewWillLayout, detect orientation

- then adapt constraint constant (or enable / disable preexisting ones) accordingly.


Do I need to do it programmatically ?


EDITED

I may have found my error, based on wrong understanding on how those variations work.


I had first defined constraints variations for hCwC and hCwR. And enable.

Then I decided to change to wR only.

And I disabled those 2 other.

I thought that removed the constraints. ERROR: they are still there and create problem. I had to remove (click on x) to get corret situation.

Accepted Reply

With this correction (suppressing constraints that are not enabled), I got the result with using hC or hR.


My mistake !

Replies

With this correction (suppressing constraints that are not enabled), I got the result with using hC or hR.


My mistake !