我尝试将shouldAutorotate设置为false
 UIInterfaceOrientationLandscapeRight的supportedInterfaceOrientations

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationLandscapeRight;
}

最佳答案

supportInterfaceOrientations就足够了,只需删除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



  在ViewController中实现此方法


-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeLeft;
}

10-08 05:31