【问题标题】:How to inform the parent viewcontroller about the changed screen orientation in the modal view controller?如何通知父视图控制器模态视图控制器中更改的屏幕方向?
【发布时间】:2011-10-14 12:03:03
【问题描述】:

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

UISplitViewController 似乎没有收到有关更改方向的通知: 拆分视图控制器的第一个视图被隐藏,第二个视图没有占据整个屏幕大小。

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

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

有什么想法吗?

【问题讨论】:

    标签: ios rotation uisplitviewcontroller modalviewcontroller ios5


    【解决方案1】:

    我也有同样的问题。

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

    显示“模态”视图控制器

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

    隐藏“模态”视图控制器

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

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

    显示“模态”视图控制器:

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

    【讨论】:

      【解决方案2】:

      我在这里遇到同样的问题:Not working Orientation Notifications in VIewController under modal, with iOS5

      要在 mainController 中调用您想要的方法,您必须在模式中使用那些神奇的线条,就在控制旋转的方法中:

      yourProjectAppDelegate *delegate = (yourProjectAppDelegate*) [[UIApplication sharedApplication]delegate];
      yourProjectViewController *i=((yourProjectViewController *)delegate.window.yourConfigurationOfController);
      [i didRotateFromInterfaceOrientation:interfaceOrientationReceived];
      

      在 i id 中,您使用的对象与您使用的对象相同:yourConfigurationOfController,在本例中为 UISPlit,我认为。如果我,不是您的 uiSplit,您可以通过级联变量到达。 interfaceOrientationReceived 是在 modal 中接收到的方向:

      - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
      

      希望能帮上忙! 祝你好运!

      (对不起我的英语:))

      【讨论】:

      • 这里有一个可能的解决方案,对我来说效果很好! stackoverflow.com/questions/7846565/…
      • 不幸的是 didRotateFromInterfaceOrientation:interfaceOrientationReceived 也没有触发 UISplitViewController 的旋转。
      • 避免预设modalViewcontrolelr..jus使用一些动画在splitcontroller.view上添加子视图..
      猜你喜欢
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      • 1970-01-01
      • 2012-05-10
      • 1970-01-01
      • 2016-06-08
      • 2023-03-30
      相关资源
      最近更新 更多