IOS8. After clicking the UIViewController on the UINavigationController and rotating the device, the size is incorrect in the previous view controller

I have a UINavigationController with a root UIViewController ("root").

The root view controller pushes another child element of the UIViewController . When the “child” of the UIViewController displayed on the screen, I rotate the device and expect the “root” knob to be changed accordingly, but this will not happen. After setting a breakpoint in the root view controller:

 -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; } 

I see that the size is wrong, and the root view controller is not properly configured to resize.

Has anyone experienced this behavior?

The code is the same:

 @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } -(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { /// The size is wrong if this view controller is off screen [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 

enter image description here

Below is the NSLog size print screen after rotating the device. This is from the simulator, but the behavior on the device is the same.

enter image description here

+6
source share
2 answers

Same problem in my project. It seems that the UINavigationController and UITabBarController (maybe all viewController?) Give children the wrong size when called:

'[super viewWillTransitionToSize: size withTransitionCoordinator: coordinator];'

I fixed the problem by overriding 'viewWillTransitionToSize: withTransitionCoordinator:' in my subclass of the tabBarController controller and navigation bar (same code in both).

 - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { for (UIViewController* aViewController in self.viewControllers) { [aViewController viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; } if ([self presentedViewController]) { [[self presentedViewController] viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; } } 

I am not sure if this is the best way, if you find something better, please tell me.

+2
source

It is possible that only the window rotates. If you print it like this, it is always correct as I tested.

 [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { UIWindow *screen = [[[UIApplication sharedApplication] delegate] window]; CGSize mainWindowSize = screen.bounds.size; NSLog(@"Main window size is %@",NSStringFromCGSize(mainWindowSize)); }]; 
0
source

Source: https://habr.com/ru/post/978091/


All Articles