如何通知父视图控制器有关模态视图控制器中已更改的屏幕方向? [英] How to inform the parent viewcontroller about the changed screen orientation in the modal view controller?

查看:111
本文介绍了如何通知父视图控制器有关模态视图控制器中已更改的屏幕方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在纵向模式下呈现UISplitViewController上方的模态视图控制器。现在我将iPad旋转到横向模式并关闭模态视图控制器。

I am presenting a modal view controller above a UISplitViewController while being in Portrait mode. Now I rotate the iPad to the Landscape mode and dismiss the modal view controller.

似乎UISplitViewController没有收到有关更改方向的通知:
拆分视图控制器的第一个视图是隐藏的,第二个视图不占用整个屏幕尺寸。

It seems that UISplitViewController didn't receive the notification about the changed orientation: The 1st view of the split view controller is hidden, and the view of the 2nd is not occupying the whole screen size.

如果我来回再次旋转,则拆分视图控制器再次正常显示。

If I rotate again back and forth, the split view controller is displayed normally again.

此外,问题仅出现在iOS模拟器5.0(或运行iOS5的设备)上,而不是4.3中。

Moreover, the problem occurs only with the iOS Simulator 5.0 (or the device running iOS5) but not with the 4.3.

任何想法?

推荐答案

我遇到同样的问题。

在我的项目中,splitViewController被添加为窗口上的子视图。它通常会收到轮换消息。但是当我尝试在窗口上添加我的模态viewController作为子视图时,它不会收到旋转消息。看起来旋转消息只接收索引0的子视图。所以我用这种方式解决了它:

In my project splitViewController is added as subview on window. And it receives rotation messages normally. But when I try to add my "modal" viewController as subview on window it does not receive rotation messages. Looks like rotation messages receive only subview at index 0. So I resolved it in this way:

显示模态viewController

Showing "modal" viewController

[appDelegate.window insertSubview:myModalViewController.view atIndex:0];
[appDelegate.splitViewController.view removeFromSuperview];

隐藏modalviewController

Hiding "modal" viewController

[appDelegate.window insertSubview:appDelegate.splitViewController.view atIndex:0];
[myModalViewController.view removeFromSuperview];

但此解决方案中存在一个缺陷:modalViewController在调用<后不会立即加载其视图code> [appDelegate.window insertSubview:myModalViewController.view atIndex:0] method。为了解决这个问题,我暂时将其作为模态出现:

But there is one defect in this solution: a modalViewController will not load its view right after calling "[appDelegate.window insertSubview:myModalViewController.view atIndex:0]" method. To fix this defect I just present it as modal for a moment:

显示模态viewController:

Showing "modal" viewController:

// present and dismiss methods are called to cause viewDidLoad in modalViewController
[appDelegate.splitViewController presentModalViewController:myModalViewController animated:NO];
[appDelegate.splitViewController dismissModalViewControllerAnimated:NO];

[appDelegate.window insertSubview:myModalViewController.view atIndex:0];
[appDelegate.splitViewController.view removeFromSuperview];

这篇关于如何通知父视图控制器有关模态视图控制器中已更改的屏幕方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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