Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

koenoe commented Oct 16, 2012

You make my day!

@shabbirh

This comment has been minimized.

Copy link

shabbirh commented Feb 17, 2013

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

@lessthanyouthink

This comment has been minimized.

Copy link
Owner Author

lessthanyouthink commented Apr 1, 2013

Happy to help! :)

@viccalexander

This comment has been minimized.

Copy link

viccalexander 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

This comment has been minimized.

Copy link

jpstuehler commented Oct 2, 2013

@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

This comment has been minimized.

Copy link

ajonnet commented Jun 22, 2014

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

@masabusharif

This comment has been minimized.

Copy link

masabusharif commented Oct 27, 2014

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
You can’t perform that action at this time.