当视图控制器以模态方式呈现时,在iOS 9中未调用“viewWillTransitionToSize:”

我从另一个展示视图控制器:

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

然后在呈现的UIViewController ,方法viewWillTransitionToSize:withTransitionCoordinator:iOS 8调用,但不在iOS 9调用…

谢谢

在你当前的视图控制器中,如果你重写viewWillTransitionToSize:withTransitionCoordinator:确保你调用super 。 否则,此消息不会传播给子视图控制器。

对于Objective-C

 - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; // Your other code ... 

Swift

 override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { super.viewWillTransition(to: size, with: coordinator) // Your other code ... } 

可能看起来是一个微不足道的情况,但使用iPad时,请检查用户是否未在设置或控制面板或侧面button中激活旋转locking