【问题标题】:Interface orientation issue in ipad ios 5.1ipad ios 5.1 中的界面方向问题
【发布时间】:2012-11-20 10:36:52
【问题描述】:

我为 iPhone 和 iPad 创建了一个通用应用程序。在这个应用程序中,iPhone 是navigation 类型,iPad 是tab bar 类型。 iPhone 支持横向和纵向,iPad 应用程序仅支持横向。

在 iPad 中,我在登录窗口(当前模型视图)之后显示TabBarController,当我第一次运行 iPad 应用程序时,它总是以纵向模式运行。即使我将方向模式设置为横向,也应该自动旋转横向。

所以请任何人建议我哪里错了,或者我如何在横向模式下强制显示视图。

【问题讨论】:

    标签: iphone ipad orientation uiinterfaceorientation


    【解决方案1】:

    我使用下面的代码强行改变了方向。它对我来说很好用:

    if ([[UIDevice currentDevice] respondsToSelector:@selector (setOrientation:)]) {
      SEL selector = NSSelectorFromString (@" setOrientation:");
      NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
      [invocation setSelector:selector];
      [invocation setTarget:[UIDevice currentDevice]];
      int Val = UIInterfaceOrientationLandscapeRight;
      [invocation setArgument:& val atIndex:2];
      [invocation invoke];
     }
    

    谢谢

    【讨论】:

    • 这符合审查指南安全吗?这是私有 API
    • 不过,它还是一个私有 API,总有一天它可能会消失。最好将适当的CGAffineTransform 应用于视图和子视图并更改状态栏方向。
    【解决方案2】:

    只需在您的 applicationdelegate.m 文件中添加以下代码

    self.window.rootViewController = self.navController;
    
    and also remove [self.window addSubview:self.navController.view];
    
    this will definitely working.. 
    

    【讨论】:

    • 已经在这样做了。在 ipad 的情况下:self.window.rootViewController = self.tabBarController;和 iphone self.window.rootViewController = self.navigationController;
    • 应用是通用的。 iphone中的navigationcontroller和ipad中的tabbarcontroller。在 ipad 中完成上述操作后,它的非方向问题没有得到解决。
    猜你喜欢
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多