Iphone – UIViewController loads rotated to landscape but only supports portrait

iphoneorientationuiviewcontroller

Is there a way to load a portrait only view controller in portrait orientation even though the parent view controller (and phone) is in landscape orientation?

This particular UIViewController only fits in Portrait mode (it's a color picker), so the code in shouldAutorotateToInterfaceOrientation: returns YES only for portrait orientations. That works fine if you turn the phone while the view is already loaded, it stays in portrait, but it doesn't help if the phone is already in landscape when the view's NIB is loaded.

When the screen is already in landscape orientation when the ViewController is loaded, the view is in portrait layout and the bottom half of the view is cutoff. I tried coming up with a landscape layout but the segmented control is a problem.

EDIT – I've tried using setStatusBarOrientation in viewWillAppear but it only affects the status bar, the navigation bar and view are still rotated for landscape.

This happens with 3.1.3 and 4.0 on the iPhone.

Best Answer

If it works for your app, you could consider using a modal view controller instead. IIRC presenting a modal view controller does handle rotating properly.

Related Topic