Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lessthanyouthink/3842178 to your computer and use it in GitHub Desktop.
Save lessthanyouthink/3842178 to your computer and use it in GitHub Desktop.
A simple UINavigationController subclass to handle iOS 6's orientation changes better.
//
// CJProperRotationNavigationController.h
//
// Created by Charles Joseph on 2012-10-01.
//
#import <UIKit/UIKit.h>
@interface CJProperRotationNavigationController : UINavigationController
@end
//
// CJProperRotationNavigationController.m
//
// Created by Charles Joseph on 2012-10-01.
//
#import "CJProperRotationNavigationController.h"
@implementation CJProperRotationNavigationController
- (BOOL)shouldAutorotate {
if (self.topViewController != nil)
return [self.topViewController shouldAutorotate];
else
return [super shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
if (self.topViewController != nil)
return [self.topViewController supportedInterfaceOrientations];
else
return [super supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
if (self.topViewController != nil)
return [self.topViewController preferredInterfaceOrientationForPresentation];
else
return [super preferredInterfaceOrientationForPresentation];
}
@end
@koenoe
Copy link

koenoe commented Oct 16, 2012

You make my day!

@shabbirh
Copy link

Thank you :) You made my day - much respect :)

@lessthanyouthink
Copy link
Author

Happy to help! :)

@vicc
Copy link

vicc commented Jul 1, 2013

Hey there! Where would I add this in my project? I'm using storyboards, and don't have an actual NavigationController.h/.m file. Thanks!

Would I just assign it to my Navigation Controller, that's inside my storyboard? Thanks!

@jpstuehler
Copy link

@VAlexander You can put this code into a category and you'll get the very same effect. No need to subclass all your UINavigationControllers.

@ajonnet
Copy link

ajonnet commented Jun 22, 2014

How can we make NavController to re-evaluate its orientation when it loads another view controller?

@masabusharif
Copy link

Any Idea how to make this work if i have a UITabBarController?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment