My app build with ECSlidingViewController 2.0 as the sliding menu. I would like to disable the rotate for only one UIViewController . all my UIViewController start with UINavigationController.
I have make a SubClass of UINavigationController to implement the methods and assign the subclass to all UINavigationController in the sotryboard. but it does not work. it seems the code not triggered.
Inside MyNavigationController.m :
#import "MyNavigationController.h"
#import "ContactUsViewController.h"
@interface MyNavigationController ()
@end
@implementation MyNavigationController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (BOOL)shouldAutorotate {
NSLog(self.topViewController.description);
if ([self.topViewController isMemberOfClass:[ContactUsViewController class]]){
return NO;
}else{
return YES;
}
}
@end
ContactUsViewController is the UIViewController i don't want to rotate.
5 steps (I am running with Storyboard and IOS 7)
MyECSlidingViewController.m
-(BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
MyNavigationController.m
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
YourViewController.m
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
Hope it helps !