1

I need to have two entirely different layouts for portrait and landscape screen in my iOS app. For example in Calculator App in iOS: Portrait Screen: Portrait in Landscape Screen: Landscape This Alternative iOS layouts for portrait and landscape storyboard is not working because I can't find that functionality in XCode 10.X.

Salman Khalid
  • 543
  • 5
  • 23

1 Answers1

1

The only way I can think of is to place a piece of code to UIViewController.viewDidLayoutSubviews() or UIView.layoutSubviews(). The code could look something like this:

if frame.size.width > frame.size.heigh {
   // adjust for landscape
} else {
   // adjust for portrait
}
layoutIfNeeded()

Please note that this will not work if you try to do it in viewDidLoad() as the width and height may not be defined at that point. Also, in UIViewController it's 'view.frame.size.width' and view.layoutIfNeeded()

I do something similar to adjust UI for iPhone SE in my app and it works fine.

The "adjusting" can be as simple as changing some constraints or as complex as removing some views and/or adding others.

Also, this is different from "traits". I'd probably advice to explore traits before going down this road.