ios - 在 iOS 13 的 iPhone 上将纵向 View Controller 推到横向 View Controller 上

标签 ios objective-c uiviewcontroller ios13

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

我在这里寻找类似的问题,但它们都是旧的,而且这似乎是 iOS 13 特有的。请不要告诉我重新设计界面——我已经尝试询问客户并被告知他们想要当前行为保留。 (由于底层架构需要, View 位于单独的 Storyboard中。)

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

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

显示该问题的简化项目可在 https://github.com/dpreuitt/testPortrait.git 上公开获得。

这是一些代码:

景观 View Controller :

- (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];
    });
}

纵向 View Controller :

- (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”)

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

最佳答案

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

关于ios - 在 iOS 13 的 iPhone 上将纵向 View Controller 推到横向 View Controller 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58239820/

相关文章:

objective-c - 如何仅根据名称在应用程序中设置图标

ios - 当我给UIImageView动画时,为什么UIImage引用会更改?

ios - iPhone 6/6plus 中 SKScene 中的标签未完全对齐

ios - 将单元格的高度设置为等于标签内容

objective-c - 方法 "shouldChangeTextInRange"和 "stringByReplacingCharactersInRange"是如何工作的?

objective-c - 在 Objective-C iPad 开发中发布

ios - 在 for 循环中调用 setNeedsDisplay

ios - 在 iOS 应用程序中以编程方式注销

ios - 无法识别的选择器发送到实例 - UIViewController

iphone - 如何禁用 MFSideMenu 类中某些 View Controller 的平移模式?