Force controllers to Change their orientation in Either Portrait or Landscape

前端 未结 2 443
执念已碎
执念已碎 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:45
    - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);//choose portrait or landscape
    }
    - (BOOL) shouldAutorotate{
    return NO;
    }
    - (NSUInteger) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;//choose portrait or landscape, same as above
    }
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题