Search code examples
iosobjective-cuiviewcontrollerios13

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


I have some code that was working perfectly until I updated to iOS 13 and now it doesn't work correctly and I need help to fix it. I have a Landscape oriented view that pushes a Portrait view . After updating to iOS 13, the pushed view no longer shows as portrait on iPhone, it is landscape. How can I force it to be portrait orientation?

I looked for similar issues here, but they were all old and this seems to be specific to iOS 13. Please don't tell me to redesign the interface--I already tried asking the customer and was told that they want the current behavior preserved. (The views are in separate storyboards because of the underlying architecture needs.)

Hopefully there's some simple solution I have missed. Thank you!

The project file supports all orientation except upside-down Portrait.

A simplified project that shows the issue is publicly available at https://github.com/dpreuitt/testPortrait.git

Here's some code:

LandscapeViewController:

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

Portrait 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;
}

(In the complete project, the code to push may be triggered from a background thread, thus the need to "get_main_queue")

The sample project has a landscape view with a button. On clicking the button a portrait-oriented view controller should appear, but unfortunately appears in Landscape mode.


Solution

  • Setting the UIModalPresentationStyle on the portrait storyboard to FullScreen made it work.