Force controllers to Change their orientation in Either Portrait or Landscape

前端 未结 2 449
执念已碎
执念已碎 2020-12-06 23:03

I have following Controllers, (I have selected all types orientation modes in iPad)

Here is my iPad Storyboard layout

Custom NavigationController >         


        
2条回答
  •  不知归路
    2020-12-06 23:48

    There is one trick.

    Fetch the status bar from the Application and rotate it.

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
    

    Create and display and dismiss an empty view controller modally.

    UIViewController *mVC = [[UIViewController alloc] init];
    [self presentModalViewController:mVC animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    

    Now your device shoud have been forced to rotate. You could now segue to a proper view controller or push one using the navigation controller.

提交回复
热议问题