当视图控制器以模态方式呈现时

当视图控制器以模态方式呈现时

本文介绍了" viewWillTransitionToSize:"当视图控制器以模态方式呈现时,在iOS 9中不调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提供另一个视图控制器:

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];
}

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

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

谢谢

推荐答案

在当前视图控制器中,如果覆盖 viewWillTransitionToSize:withTransitionCoordinator:,请确保调用 super 。否则,此消息将不会传播到子视图控制器。

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.

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 ...
}

这篇关于&QUOT; viewWillTransitionToSize:&QUOT;当视图控制器以模态方式呈现时,在iOS 9中不调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 21:31