如何通过MMDrawerController禁用特定ViewControllers的旋转功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计401个文字,预计阅读时间需要2分钟。
要解决《使用MMDrawerController如何禁用旋转是一些ViewControllers?》的问题,您可以采取以下几种方法:
1. 修改ViewControllers的`shouldAutorotate`属性: - 在您需要禁用旋转的ViewControllers中,将`shouldAutorotate`属性设置为`NO`。 swift override var shouldAutorotate: Bool { return false }
2. 覆盖MMDrawerController的`shouldAutorotate`方法: - 如果您想要在整个MMDrawerController中禁用旋转,可以在控制器中重写`shouldAutorotate`方法。 swift override var shouldAutorotate: Bool { return false }
3. 在AppDelegate中设置根ViewController的偏好设置: - 通过在AppDelegate中设置根ViewController的偏好设置来禁用旋转。 swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // 设置根ViewController let rootViewController=YourRootViewController() window?.rootViewController=rootViewController
// 禁用旋转 rootViewController.preferredInterfaceOrientationForPresentation=.portrait rootViewController.supportedInterfaceOrientations=.portrait
return true }
4. 使用UIInterfaceOrientationMask枚举: - 在AppDelegate中设置根ViewController的`supportedInterfaceOrientations`,以限制方向。 swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let rootViewController=YourRootViewController() window?.rootViewController=rootViewController
rootViewController.supportedInterfaceOrientations=.portrait return true }
选择适合您应用程序的方法,以禁用旋转并确保用户体验。
我在我的应用程序中使用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!我已经检查这个和这个和这个,但没有任何帮助.
本文共计401个文字,预计阅读时间需要2分钟。
要解决《使用MMDrawerController如何禁用旋转是一些ViewControllers?》的问题,您可以采取以下几种方法:
1. 修改ViewControllers的`shouldAutorotate`属性: - 在您需要禁用旋转的ViewControllers中,将`shouldAutorotate`属性设置为`NO`。 swift override var shouldAutorotate: Bool { return false }
2. 覆盖MMDrawerController的`shouldAutorotate`方法: - 如果您想要在整个MMDrawerController中禁用旋转,可以在控制器中重写`shouldAutorotate`方法。 swift override var shouldAutorotate: Bool { return false }
3. 在AppDelegate中设置根ViewController的偏好设置: - 通过在AppDelegate中设置根ViewController的偏好设置来禁用旋转。 swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // 设置根ViewController let rootViewController=YourRootViewController() window?.rootViewController=rootViewController
// 禁用旋转 rootViewController.preferredInterfaceOrientationForPresentation=.portrait rootViewController.supportedInterfaceOrientations=.portrait
return true }
4. 使用UIInterfaceOrientationMask枚举: - 在AppDelegate中设置根ViewController的`supportedInterfaceOrientations`,以限制方向。 swift func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let rootViewController=YourRootViewController() window?.rootViewController=rootViewController
rootViewController.supportedInterfaceOrientations=.portrait return true }
选择适合您应用程序的方法,以禁用旋转并确保用户体验。
我在我的应用程序中使用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!我已经检查这个和这个和这个,但没有任何帮助.

