OGeek|极客世界-中国程序员成长平台

标题: ios - 如何通知父 View Controller 模态视图 Controller 中更改的屏幕方向? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:21
标题: ios - 如何通知父 View Controller 模态视图 Controller 中更改的屏幕方向?

当处于纵向模式时,我在 UISplitViewController 上方展示了一个模态视图 Controller 。现在我将 iPad 旋转到横向模式并关闭模态视图 Controller 。

UISplitViewController 似乎没有收到有关更改方向的通知: Split View Controller 的第一个 View 被隐藏,第二个 View 没有占据整个屏幕大小。

如果我再次来回旋转, Split View Controller 再次正常显示。

此外,该问题仅出现在 iOS Simulator 5.0(或运行 iOS5 的设备)上,而不会出现在 4.3 上。

有什么想法吗?



Best Answer-推荐答案


我也有同样的问题。

在我的项目中 splitViewController 被添加为窗口上的 subview 。它正常接收轮换消息。但是当我尝试将我的“模态” View Controller 添加为窗口上的 subview 时,它不会收到旋转消息。看起来旋转消息仅在索引 0 处接收 subview 。所以我以这种方式解决了它:

显示“模态” View Controller

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

隐藏“模态” View Controller

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

但是这个解决方案有一个缺陷:modalViewController 在调用“[appDelegate.window insertSubview:myModalViewController.view atIndex:0]”方法后不会立即加载它的 View 。为了修复这个缺陷,我暂时将其呈现为模态:

显示“模态” View Controller :

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

关于ios - 如何通知父 View Controller 模态视图 Controller 中更改的屏幕方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7767302/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4