UINavigationController and Rotation

Recently working on a project that needs a video displayed from a table view inside of a UINavigationController stack. The video needs to be in Landscape mode, while the rest of the project can be in Portrait or Landscape. The view controllers are pushed onto the stack, and each of the view controllers overrode the shouldAutorotateToInterfaceOrientation: method. The landscape controller had return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);; the rest of the controllers simply returned YES. So far, so good.

Here’s the problem. The view controller that contained the video (aka VideoViewController) arranged its elements in landscape mode, but started in potrait mode. Rotating it to Landscape mode corrected the issue, then rotating it back to Portrait mode, it still looked ok:

I could not make this work using the pushViewController method on the root view controller’s navigationController. But, for some strange reason, presentModalViewController: presented this view in the correct orientation. So the table view gets pushed onto the NavigationController with pushViewController and the VideoViewController gets presented as a modal view. The interesting thing about it is if you specify YES for the animated parameter, it doesn’t look like a modal view controller — meaning that it doesn’t pop up from the bottom like normal modal VCs, but rather from the side, and doesn’t look unnatural.

This is only a workaround until I can figure out why a regular pushViewController call doesn’t rotate the view, and I was lucky enough that in this instance a modal controller worked out well.

Leave a Reply