我尝试将 shouldAutorotate 设置为 false supportedInterfaceOrientations 到 UIInterfaceOrientationLandscapeRight
-(BOOL)shouldAutorotate{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationLandscapeRight;
}
最佳答案
supportedInterfaceOrientations 就够了,去掉 shouldAutorotate 就可以了。 或者你可以这样做。
NavigationController.m
@interface NavigationController : UINavigationController
@end
@implementation NavigationController
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return [self.topViewController supportedInterfaceOrientations];
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
[super pushViewController:viewController animated:animated];
[self refreshOrientation];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
id vc = [super popViewControllerAnimated:animated];
[self refreshOrientation];
return vc;
}
- (NSArray<UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated {
id vcs = [super popToViewController:viewController animated:animated];
[self refreshOrientation];
return vcs;
}
- (NSArray<UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
id vcs = [super popToRootViewControllerAnimated:animated];
[self refreshOrientation];
return vcs;
}
- (void)refreshOrientation {
UIViewController *vc = [UIViewController new];
[UIViewController attemptRotationToDeviceOrientation];
[self presentViewController:vc animated:NO completion:nil];
[vc dismissViewControllerAnimated:NO completion:nil];
}
@end
in ViewController implement this method
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft;
}
关于ios - 如何将一个 View Controller 方向单独强制/锁定到 landscapeRight?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41569848/