"viewWillTransitionToSize:" not called in iOS 9 when the view controller is presented modally

AppsDev picture AppsDev · Oct 1, 2015 · Viewed 10.9k times · Source

I present a view controller from another one:

- (void)showModalView
{
   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
   MySecViewController *mySecViewController = [storyboard instantiateViewControllerWithIdentifier:@"secController"];
   mySecViewController.delegate = self;
   [self presentViewController:mySecViewController animated:YES completion:nil];
}

Then in the presented UIViewController, the method viewWillTransitionToSize:withTransitionCoordinator: is called in iOS 8 but not in iOS 9...

Thanks

Answer

Yuchen Zhong picture Yuchen Zhong · Jan 13, 2016

In your current view controller, if you override viewWillTransitionToSize:withTransitionCoordinator:, make sure you call super. Otherwise, this message won't get propagated to children view controllers.

For Objective-C:

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

    // Your other code ... 

And Swift:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransition(to: size, with: coordinator)

    // Your other code ...
}