Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad Landscape and Portrait different layouts with Size Class

How to design iPad Landscape and Portrait screens with different Layouts using Size class. I could find only w-regular and h-regular for both orientations. Example: I need to align 2 views vertically in portrait and horizontally in landscape using Size Class

like image 744
Harish Kumar Kailas Avatar asked Sep 07 '25 18:09

Harish Kumar Kailas


2 Answers

Finally I found a solution :

if traitCollection.verticalSizeClass == .Regular && traitCollection.horizontalSizeClass == .Regular {

     var orientation:UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation;
     if orientation == UIInterfaceOrientation.LandscapeLeft || orientation == UIInterfaceOrientation.LandscapeRight {
            // orientation is landscape


     }  else {
            // orientation is portrait

     }
}
like image 109
cmii Avatar answered Sep 10 '25 06:09

cmii


It appears to be Apple's intent to treat both iPad orientations as the same -- but as a number of us are finding, there are very legitimate design reasons to want to vary the UI layout for iPad Portrait vs. iPad Landscape.

However, please see this answer for another approach to adapting size classes to do what we need: https://stackoverflow.com/a/28268200/4517929

like image 37
RonDiamond Avatar answered Sep 10 '25 08:09

RonDiamond