Different iPad layouts for landscape/portrait

Having been working on other platforms for a while, I'm not that familiar with the newer declarative ways of dealing with orientations (ie. size classes & autolayout rather than responding to notifications).


Given that the iPad is of regular size class in both width and height, how would I go about declaring different layouts for portrait vs landscape orientations?

Replies

Well, it seems you just can't ... At least not on IB 😠


For Apple, both "should" be seen as the same, and there is no way to have "orientation" in IB.

(of course that's silly, because even Apple's own SDKs treat them differently, even on IB ... For example the UISplitViewContoller).


You'll sadly have to deal with it in code, in "viewWillTransitionToSize:withTransitionCoordinator:" ... You can check if it's an iPad, and if size.width > size.height (landscape) or else (portrait), and you apply whatever layout you want.


This beats the whole idea of designing in IB, and can even cause problems with the new split screen.

Thanks, that's helpful. Disappointing though! I was hoping to go all-in with the declarative approach, which up to now was looking pretty nice to me. As for idea that 4:3 and 3:4 aspect ratios should have the same layouts, if that is indeed Apple's notion, well, it's daft 😝

You're welcome, happy if that helped even a little.


The problem, is you'd have to deal now with multitasking (split view, half on portrait and landscape, third and two thirds in landscape).

The funny part is that half split on an iPad pro is supposed to equal two ipads in portrait, yet it doesn't get the Regular x Regular, but Compact x Regular ... which ends up loading the layout of an iPhone 😟


Dealing with all these possibilities in code diffinetly gives a dirty result, and makes the whole projec hardly future proof and hard to modify (code + IB).

> The funny part is that half split on an iPad pro is supposed to equal two ipads in portrait, yet it doesn't get the Regular x Regular, but Compact x Regular ... which ends up loading the layout of an iPhone


Seriously??? That right there is the nail in the coffin for size classes. That is just stupid.

Ugh, that seems ill thought out. I suppose it will mature (think of Xcode's early attempts at layout constraints).


Fortunately for my immediate purposes split-screen isn't really an issue (not a requirement for this particular client app).

> split-screen isn't really an issue (not a requirement


You do know that users can split the screen to run two apps side-by-side, right?

Late to the party but I think what you describe :

> The funny part is that half split on an iPad pro is supposed to equal two ipads in portrait, yet it doesn't get the Regular x Regular, but Compact x Regular ... which ends up loading the layout of an iPhone



Is actually an IB bug. When you run the app, split the screen in half and ask for view.traitCollection.horizontalSizeClass you actually get regular not compact !