Browse files

Orientation Respectful Navigation Controller post

Signed-off-by: Levi Brown <>
  • Loading branch information...
1 parent d8b44c3 commit e72657ffcfe28e7ce3335ec54577501ce4ef6888 Levi Brown committed Nov 16, 2012
@@ -0,0 +1,28 @@
+layout: post
+title: "Orientation Respectful UINavigationController"
+date: 2012-11-16 13:39
+comments: false
+While working on a project for iOS 6 I ran into an interesting issue with rotations.
+I wanted one of my views to rotate, but not others, and since `UIViewController`'s `shouldAutorotateToInterfaceOrientation:` is deprecated in iOS 6 and the docs point at overriding `shouldAutorotate`, I swapped them out. But... `shouldAutorotate` didn't get called. Hrm? A little poking around and I see this in the [iOS 6 release notes](
+> Now, iOS containers (such as UINavigationController) do not consult their children to
+> determine whether they should autorotate. By default, an app and a view controller’s
+> supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad
+> idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.
+So, because my views are "underneath" a `UINavigationController` their `shouldAutorotate` methods are not getting called, only the parent `UINavigationController` is queried. That seems like an odd behavior to me, but it's easy enough to remedy. A subclass of `UINavigationController` which respects the desired behavior of the top view controller is all that's needed.
+This UINavigationController subclass will query it's topmost view controller for desired rotation behavior, unlike the default implementation:
+{% gist 4090689 %}
+To use, simply include the source in your project, and select `OrientationRespectfulNavigationController` as the class to use in place of each `UINavigationController` you want to have this behavior:
+{% img images/posts/2012-11-16-orientationrespectfulnavigationcontroller/IBClassConfig.png 'XCode configuration for UINavigationController class override' 'XCode configuration for UINavigationController class override' %}
+NOTE: I'm by no means the first to figure this out. StackOverflow [has]( [several]( [posts]( which illustrate the problem and solution.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e72657f

Please sign in to comment.