使用 MMDrawerConroller 如何禁用旋转是一些 ViewControllers?
Using MMDrawerConroller how to disable rotation is some ViewControllers?
我在 this link
的应用程序中使用 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;
}
我想问题出在根源ViewController,也就是MMDrawerViewController!
我已经检查过 this and this and this 但没有任何帮助。
在 MMDrawerController
中覆盖以下方法,例如。
-(BOOL)shouldAutorotate {
return [self.centerViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.centerViewController supportedInterfaceOrientations];
}
试试这个,如果不成功,那么你需要继承 UINavigationController 并覆盖这些方法,然后你的视图控制器方向设置将在层次结构中传递。
如果问题仍然存在,则子类化 UINavigationController 并实现
-(BOOL)shouldAutorotate {
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
我认为 UINavigationController 会自动控制,但如果它不能控制,您可以子类化。
我在 this link
的应用程序中使用 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;
}
我想问题出在根源ViewController,也就是MMDrawerViewController!
我已经检查过 this and this and this 但没有任何帮助。
在 MMDrawerController
中覆盖以下方法,例如。
-(BOOL)shouldAutorotate {
return [self.centerViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.centerViewController supportedInterfaceOrientations];
}
试试这个,如果不成功,那么你需要继承 UINavigationController 并覆盖这些方法,然后你的视图控制器方向设置将在层次结构中传递。
如果问题仍然存在,则子类化 UINavigationController 并实现
-(BOOL)shouldAutorotate {
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
我认为 UINavigationController 会自动控制,但如果它不能控制,您可以子类化。