我的应用程序使用ECSlidingViewController 2.0作为滑动菜单构建。我想只为一个UIViewController禁用旋转。我的所有UIViewController都以UINavigationController开头。
我已经创建了一个UINavigationController的SubClass来实现这些方法,并将子类分配给sotryboard中的所有UINavigationController。但它不起作用。似乎代码没有被触发。
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是我不想旋转的UIViewController。
答案 0 :(得分:3)
5个步骤(我正在使用Storyboard和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;
}
希望它有所帮助!