1

I am confused if 'Vary for Traits' is the right thing to define different set of layout constraints for Portrait & Landscape mode on iPhone. My objective is to have different layouts for Portrait & Landscape modes on the iPhone (doesn't matter on iPad). I tried 'Vary for Traits' and define different set of NSLayoutConstraints for Portrait & Landscape modes but it seems to be not working. Basically if I have constraints P1 & P2 active for portrait mode and C1 & C2 for landscape mode for the same view, that should do the job. Is 'Vary for Traits' really meant for this job?

Also how do I undo any variations I might have already added using 'Vary for Traits'?

Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
  • Yes. That's what Vary for Traits does. Look at your autolayout constraints and you'll see your extra traits added if you modified that constraint under "Vary for Traits." You can delete them there. – Rob Napier Sep 13 '17 at 22:36
  • I think it's not as simple as one would expect when it comes to UIStackView. I posted a separate question for the same here: – Deepak Sharma Sep 14 '17 at 10:05
  • https://stackoverflow.com/questions/46214272/uistackview-autolayout-constraints – Deepak Sharma Sep 14 '17 at 10:05

1 Answers1

1

You need to do the following -

  • Set the constraint in portrait mode.
  • Select the Landscape mode.
  • Disable constraints which you set in portrait mode.
  • Assign new constraints for landscape.
  • Go back in Portrait mode and Disable the constraints which you set in Landscape mode.

That's it.

Hope it works.

Feel free to comment if you have any confusion..