IOS 8: introducing a modal view controller in a portrait causes the navigation bar to resize the base landscape navigation controller

In iOS 8, I have strange behavior regarding the navigation bar and orientation changes.

I have a navigation controller that reports on the supported orientation of the UIInterfaceOrientationMaskLandscapeRight interface. The navigation bar has the expected height for landscape orientation (unfortunately, I have no right to post screenshots).

Then I start a modal view of the view controller, which only supports UIInterfaceOrientationMaskPortrait . When the presentation animation starts, it seems that the metrics of the main navigation controller are changed to portrait presentation, since the height of the navigation panel increases to the size of its portrait, as shown above.

iOS 7 does not exhibit this behavior. What am I missing? I want to restore the old behavior.

Here is the complete code for a simple example above:

 @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; DOGButtonViewController *root = [DOGButtonViewController new]; DOGOrientedNavigationController *navi = [[DOGOrientedNavigationController alloc] initWithRootViewController:root]; navi.allowedInterfaceOrientations = UIInterfaceOrientationMaskLandscapeRight; self.window.rootViewController = navi; [self.window makeKeyAndVisible]; return YES; } - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait; } @end @implementation DOGOrientedNavigationController - (NSUInteger)supportedInterfaceOrientations { return self.allowedInterfaceOrientations; } @end @implementation DOGButtonViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Button View Controller"; } - (BOOL)prefersStatusBarHidden { return YES; } - (IBAction)buttonClicked:(id)sender { DOGPortraitViewController *vc = [DOGPortraitViewController new]; [self presentViewController:vc animated:YES completion:nil]; } @end @implementation DOGPortraitViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Portrait Title"; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (IBAction)buttonClicked:(id)sender { [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; } - (BOOL)prefersStatusBarHidden { return YES; } @end 

In a more complex setup, I also experience the text in the UIWebView contained in the navigation controller, which scales when the portrait is modal. If the modality is rejected, the text does not change to its original size.

+8
uiviewcontroller ios8 uinavigationcontroller presentviewcontroller
source share
1 answer

Due to the lack of a better option, I worked a bit on this. Basically, before I show the modal view, I take a screenshot and put it on top of the view controller.

Obviously I need to delete this screenshot when the view reappears

  func showScreenShot () { let image = screenShot() self.screenShotImageView = UIImageView(image: image) self.view.addSubview(self.screenShotImageView!) } func screenShot () -> UIImage { UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, true, UIScreen.mainScreen().scale) self.view.layer.renderInContext(UIGraphicsGetCurrentContext()) let image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image } func removeScreenShot () { if let screenImageView = self.screenShotImageView { screenImageView.removeFromSuperview() self.screenShotImageView = nil } } 
0
source share

All Articles