在 iOS 13 中的 iPhone 上将纵向视图控制器推到横向视图控制器上

Push a portrait View controller over a Landscape View controller on iPhone in iOS 13

我有一些代码在我更新到 iOS 13 之前一直运行良好,但现在它无法正常运行,我需要帮助来修复它。我有一个 Landscape oriented view 推 Portrait view 。更新到 iOS 13 后,推送的视图在 iPhone 上不再显示为纵向,而是横向。我怎样才能强制它为纵向?

我在这里寻找类似的问题,但它们都是旧的,而且这似乎是特定于 iOS 13.请不要告诉我重新设计界面——我已经试过询问客户和被告知他们希望保留当前的行为。 (由于底层架构需要,视图位于单独的故事板中。)

希望有一些我遗漏的简单解决方案。谢谢!

项目文件支持除倒置纵向以外的所有方向。

可在 https://github.com/dpreuitt/testPortrait.git

上公开显示该问题的简化项目

这是一些代码:

横向视图控制器:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (BOOL) shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}


- (IBAction)pushPortrait:(id)sender
{
    UIStoryboard *portraitStoryboard = [UIStoryboard storyboardWithName:@"Portrait" bundle:nil];
    PortraitViewController* loginController = [portraitStoryboard instantiateViewControllerWithIdentifier:@"PortraitVC"];
    dispatch_async(dispatch_get_main_queue(), ^(){
        [self presentViewController:loginController animated:YES completion:nil];
    });
}

纵向视图控制器:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (BOOL) shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

(在完整的项目中,推送的代码可能是后台线程触发的,所以需要"get_main_queue")

示例项目有一个带按钮的横向视图。单击按钮时应该会出现一个纵向视图控制器,但不幸的是出现在横向模式下。

将肖像故事板上的 UIModalPresentationStyle 设置为全屏使其工作。