Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
OrientationRespectfulNavigationController
//
// OrientationRespectfulNavigationController.h
//
// Created by Levi Brown on 11/15/12. @levigroker
// This work is licensed under a Creative Commons Attribution 3.0 Unported License
// http://creativecommons.org/licenses/by/3.0/
// Attribution to Levi Brown (@levigroker) is appreciated but not required.
//
/*
This NavigationController will query it's topmost view controller for desired rotation behavior,
unlike the default implementation.
From the iOS 6 release notes:
http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
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.
*/
#import <UIKit/UIKit.h>
@interface OrientationRespectfulNavigationController : UINavigationController
@end
//
// OrientationRespectfulNavigationController.m
//
// Created by Levi Brown on 11/15/12. @levigroker
// This work is licensed under a Creative Commons Attribution 3.0 Unported License
// http://creativecommons.org/licenses/by/3.0/
// Attribution to Levi Brown (@levigroker) is appreciated but not required.
//
/*
This NavigationController will query it's topmost view controller for desired rotation behavior,
unlike the default implementation.
From the iOS 6 release notes:
http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
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.
*/
#import "OrientationRespectfulNavigationController.h"
@implementation OrientationRespectfulNavigationController
- (BOOL)shouldAutorotate
{
BOOL retVal = [super shouldAutorotate];
if (self.topViewController)
{
retVal = [self.topViewController shouldAutorotate];
}
return retVal;
}
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger retVal = [super supportedInterfaceOrientations];
if (self.topViewController)
{
retVal = [self.topViewController supportedInterfaceOrientations];
}
return retVal;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
UIInterfaceOrientation retVal = [super preferredInterfaceOrientationForPresentation];
if (self.topViewController)
{
retVal = [self.topViewController preferredInterfaceOrientationForPresentation];
}
return retVal;
}
@end
@levigroker
Owner

Updated to handle the potential case that there is no topViewController present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.