【问题标题】:Modal UINavigationController presented in wrong orientation模态 UINavigationController 以错误的方向呈现
【发布时间】:2013-01-14 13:57:43
【问题描述】:

我有一个 iPad 应用程序支持所有方向的设置。在应用程序的一部分中,点击会触发需要导航控制器的模态视图控制器的显示。所以我基本上是在做:

UIViewController *myViewController = [[UIViewController alloc] initWithNibName:@"MyView" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:myViewController];
NSLog(@"%d", nav.interfaceOrientation);

[window.rootViewController presentModalViewController:nav animated:YES];

当 iPad 处于纵向(主页按钮)时,这可以正常工作。在任何其他方向,模态视图总是从主页按钮纵向显示,而不是设备的当前底部。

如果我完全跳过导航控制器并仅以模态方式显示myViewController,它会正确显示。

所以,我尝试继承 UINavigationViewController 并显式覆盖 shouldAutorotate:supportedInterfaceOrientations: 方法,但这没有任何效果。有趣的是,如果我重写 viewWillAppear 方法并记录 interfaceOrientation 属性的值,这总是返回 1,即使它在从上面的代码访问它时返回正确的值。

我还检查了 Info.plist 是否支持所有方向。

那么,还有什么可能导致这种行为?非常感谢任何帮助。

【问题讨论】:

    标签: ios6 uinavigationcontroller rotation presentmodalviewcontroller


    【解决方案1】:

    尝试在导航控制器的子类中实现preferredInterfaceOrientationForPresentation。

    以下内容对我有用:

    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
        return self.interfaceOrientation;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      • 2011-08-05
      • 2012-01-18
      • 1970-01-01
      • 1970-01-01
      • 2011-04-09
      相关资源
      最近更新 更多