3

I am working on an iPad app and want to support both portait and landscape orientation.

Currently, I am seeing three ways to handle orientation:

1) Apple recommends using two view controllers (http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html)

2) The Beginning iPhone Dev book I have uses a single xib file with multiple UIView (one for portrait, one for landscape), swapping the view in the willAnimateRotationToInterfaceOrientation() method.

3) Others have said the "proper" way to do it was using layoutSubviews and autosizing mask.

Before, when I build an app, I would write my entire app purely in code, including interface setup and layout. The result was I ended up with a massive and very painful to tweak interface code.

Now after writing a number of apps in purely code, I kind of appreciate why there is Interface Builder - to help manage the interface and more so, a view controller should ideally only be for managing data and sending it to the views, not managing how the views should look.

Using Interface Builder, it makes sense to have two separate custom UIViews, one for portrait and one for landscape but I've been told otherwise that layoutSubview is the better option.

But if I were to use layoutSubview, that would mean I have to go back to writing and managing my interface using code, which doesn't seem right to me.

Is using layoutSubviews() really the way to go ?

I really don't see any benefit it has over other method. Some say layoutSubviews allow you to animate the transition to the other orientation.

My two interface isn't a simple resize button or text width when the device rotates. I have adjacent sliders next to text fields that should be stacked vertically when rotating to landscape and other sliders that needs to be moved to the other side of the screen etc.

edit

might be a duplicate questions of:

Handle iPhone orientation Landscape/Portrait

iPad/iPhone multiple orientations best practice?

Moderators can close if need to.

1
  • NOTE: The link under #1 was removed by Apple... (it was a really good article!)
    – benc
    Jan 12, 2017 at 23:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.