OK, this is one possible solution that works:
@interface TestVC : UIViewController @property (assign, nonatomic) UIInterfaceOrientationMask orientationMask; @end @implementation TestVC - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return _orientationMask; } @end @implementation ViewController - (IBAction)getNavigationBarHeight:(id)sender { TestVC *vc = [[TestVC alloc] init]; if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { vc.orientationMask = UIInterfaceOrientationMaskLandscapeLeft; } else { vc.orientationMask = UIInterfaceOrientationMaskPortrait; } [self presentViewController:vc animated:NO completion:^{ UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectZero]; [navBar sizeToFit]; NSLog(@"navBar frame in 'opposite' orientation: %@", NSStringFromCGRect(navBar.frame)); }]; [self dismissViewControllerAnimated:NO completion:nil]; } @end
source share