Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Storyboard Constraints/Traits for portrait and landscape view

my iOS project consists at the moment of one single UIView or UIViewController. The controller class is called MainViewController.swift. The view of the view controller has a subview which I've placed at the bottom: enter image description here

I've set the auto layout option to keep the distance of the subview for every device size the same: enter image description here

Now I want to keep the sub view always on the short side of the parent view, which means that in landscape mode the sub view show be on the right side of the parent view: enter image description here

I've checked some tutorials and other posts in the meanwhile:

  • Ray Wenderlich Tutorial
  • Stackoverflow Post

At this point it is not clear to my how to realize such a behavior best? Possibilites I've found to solve the issue:

  • Vary for traits...but how?
  • Constraints?
  • Programmatically - I think this would be the fastest solution, but I really want to use storyboards and learn the correct usage.
like image 473
Fabian Avatar asked Dec 12 '17 17:12

Fabian


1 Answers

Here you can play with size classes and traits. if you want give constraint in portrait mode you have to select compact width and regular height and for landscape compact width compact height.

Please go through following steps to constraint portrait and landscape separately.

1) Please select mode either landscape and portrait from traits.

2) Now, you can constraint each mode one by one. suppose i am giving constraint to red view in portrait mode and i will enable particular constraints for for portrait size class so it will be disable for landscape mode.

enter image description here 3)once we are finished with portrait mode i have switched to compact height compact regular size class which is landscape mode.

enter image description here

4) Now, we can constraint the landscape mode as shown in above screenshot.

As we can see constraints which is light in color are disable for current size class.

So this is how we can constraints landscape and portrait mode separately.

like image 96
Aman.Samghani Avatar answered Nov 15 '22 03:11

Aman.Samghani