7

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

The root view controller pushes another UIViewController "child". When the "child" UIViewController is on the screen , I rotate the device and expect the "root" view controller to resize accordingly but this isn't happening. After putting 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 doesn't adjust properly to the change.

Has any one experienced this behaviour?

The code is as so:

@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

Here is a print screen of the NSLog of the size after rotating the device - This is from the simulator but the behaviour is the same on the device.

enter image description here

6
  • What's your size log, what do you expect?
    – gabbler
    Nov 12, 2014 at 15:39
  • I'll add a print screen - after I had rotated the device a few times. Notice that the size is always the same.
    – Avba
    Nov 12, 2014 at 15:43
  • Yes,it is always the same size, it looks like root View controller doesn't rotate at all.
    – gabbler
    Nov 12, 2014 at 15:44
  • 1
    Yes. Seems like a bug
    – Avba
    Nov 12, 2014 at 15:45
  • @AvnerBarr how did you fix this issue? I am porting some code from the previous will/didRotate to the new viewWillTransitionToSize. I am using a UINavigationController for a drill down navigation and I need to do some things in all the stacked controllers when the device is rotated.
    – louissmr
    Apr 11, 2015 at 20:37

2 Answers 2

2

Same issue on my project. It seems that UINavigationController and UITabBarController (maybe all viewController?) give to there children the wrong size when you call :

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

I fixed the issue by overriding 'viewWillTransitionToSize:withTransitionCoordinator:' in my tabBarController and navigation bar controller subclass (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'm not sure this is the best way, if you found something better, tell me please.

0

Possibly that only the window rotate. If you print it like this, it is always correct as I have 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));

 }];
3
  • That's a hack. I don't want to put that in 20 view controllers
    – Avba
    Nov 12, 2014 at 16:07
  • All that is is dumping out the current size to the log. Nothing effected yet in this code.
    – Norman H
    Feb 11, 2015 at 21:19
  • @NormanH, this code works for me, it is put in the previous view controller, which view is off screen, if you rotate the current view, the logs is right.
    – gabbler
    Feb 12, 2015 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.