我在this链接的应用程序中使用MMDrawerController 我以这种方式在AppDelegate中设置了根ViewController:
self.leftDrawerController = [[LeftDrawerViewController alloc] init];
self.homeViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.homeViewController];
// DrawerViewController setup
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:self.navigationController
leftDrawerViewController:self.leftDrawerController];
[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[self.drawerController setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
MMDrawerControllerDrawerVisualStateBlock block; block = [[DrawerVisualStateManager sharedManager] drawerVisualStateBlockForDrawerSide:drawerSide];
if (block) {
block(drawerController, drawerSide, percentVisible);
}
}];
[self.window setRootViewController:self.drawerController];
我想在特定的ViewController中禁用旋转,我调用这些方法,它们永远不会被调用,视图仍然会旋转:
// ViewController.m
-(BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
我猜问题来自rootViewController,这是MMDrawerViewController!
我已经检查了this和this以及this,但没有任何帮助。
答案 0 :(得分:3)
MMDrawerController
中的覆盖了以下类似的方法。
-(BOOL)shouldAutorotate {
return [self.centerViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.centerViewController supportedInterfaceOrientations];
}
如果不成功则尝试此操作然后您需要继承UINavigationController并覆盖这些方法,然后您的viewcontrollers方向设置将在层次结构中传递。
答案 1 :(得分:3)
如果问题仍然存在,那么继承子类UINavigationController并实现
-(BOOL)shouldAutorotate {
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
我认为UINavigationController会自动控制,但万一你不能进行子类化。