willRotateToInterfaceOrientation 未被呈现的视图控制器调用 [英] willRotateToInterfaceOrientation not being called from presented viewcontroller

查看:19
本文介绍了willRotateToInterfaceOrientation 未被呈现的视图控制器调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ipad 上有 uiviewcontroller 具有以下配置:

I have uiviewcontroller on ipad with this configuration:

shouldAutorotate (true)支持的接口方向(UIInterfaceOrientationMaskAll)willRotateToInterfaceOrientation 中,我执行了一些技巧来调整我的界面.

shouldAutorotate (true) supportedInterfaceOrientations (UIInterfaceOrientationMaskAll) and inside willRotateToInterfaceOrientation i perform some trick to adjust my interface.

从这个控制器的子节点,我展示了一个带有这个 -poor- 代码的 QuickLookController.

From a child of this controller I show a QuickLookController with this -poor- code.

[[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:previewController animated:YES completion:nil];

但是如果我旋转我的 ipad,方法 willRotateToInterfaceOrientation 不会被调用,所以我无法调整界面.

But if I rotate my ipad the method willRotateToInterfaceOrientation not being called, So I cannot do the trick to adjust the interface.

有人可以解释一下或给我一些建议吗?谢谢

Someone can explain me or given me some advices? thanks

推荐答案

原因:这个问题可能有很多可能性.

Reason : There may be many possibilities to this problem.

1) 如果你的视图的 viewController 是其他一些 rootViewControllersubView 而不是 navigationController,那么可能有可能旋转调用不会传播到子视图的控制器.

1) If your view's viewController is a subView of some other rootViewController which is not a navigationController, then there might be chances that rotation call is not propagating to the subView's controller.

2) 我在某处读到,如果 Super 方法在需要的地方没有被正确调用,那么它可能是旋转问题的原因,这意味着视图堆栈中的所有 ViewControllers 都与自动旋转必须在方法实现中调用super 方法(即从ViewController 的viewDidLoad 调用[super viewDidLoad]).

2) Somewhere I read that if Super methods are not called properly where it is needed then it might be the cause of rotation problem, which means that all ViewControllers in view stack which are related to the autorotation must call the super methods in method implementations (i.e. calling [super viewDidLoad] from the ViewController's viewDidLoad).

您可以使用以下技巧来处理方向变化.

在 viewWillAppear 中注册一个通知程序.

Register a notifier in viewWillAppear.

-(void)viewWillAppear:(BOOL)animated{
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(orientationChanged:)  name:UIDeviceOrientationDidChangeNotification  object:nil];}

方向改变会通知下面的函数.

The orientation change will notify the below function.

- (void)orientationChanged:(NSNotification *)notification{
[self handleOrientation:[[UIApplication sharedApplication] statusBarOrientation]];}

这将调用以下方法,您可以在其中处理方向更改.

which will call the below method where you can handle the orientation changes.

   - (void) handleOrientation:(UIInterfaceOrientation) orientation {

        if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
        { 
            //handle the portrait view    
        }
        else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
        {
            //handle the landscape view 
        }
     }

这篇关于willRotateToInterfaceOrientation 未被呈现的视图控制器调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆