【问题标题】:Interface Orientation won't change to Landscape on App Launch应用启动时界面方向不会更改为横向
【发布时间】:2011-05-24 20:10:11
【问题描述】:

我遇到了一个让我发疯的问题! 我有一个以 TabBarViewController 开头的 iPad 应用程序。每个 Tab 都有自己的 ViewController 和 nib 文件。

为了使界面方向成为可能,我将所有方向添加到我的 info.plist 并将我的 TabBarController 子类化为设置:

        - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return YES;
}

如果我旋转界面,每个视图都会自动调整大小和格式,以便显示正确的方向。如果我在模拟器中测试它,一切看起来都很好,我可以在方向之间旋转。

现在让我抓狂的是:

如果我在纵向模式下启动应用程序,一切正常。但如果我在横向模式下启动,我会收到错误,我的界面方向似乎仍然是纵向,而模拟器处于横向模式!!

错误:

2011-05-24 21:50:15.011 Project[57995:207] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.

我检查了这样的方向:

    -(void)viewWillAppear:(BOOL)animated{

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];



    if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
        NSLog(@"Orientation: Landscape");
    }
    else{
        NSLog(@"Orientation: Portrait");
    }

}

如果我以横向模式启动,日志显示它处于“横向”模式,但如果我将选项卡更改为另一个选项卡,它看起来很糟糕,因为视图改为以纵向模式显示。 在更改回我要求方向的开始视图时……日志显示“纵向”……但模拟器仍然是横向!

我不明白为什么一开始的方向是纵向的,... 即使我从横向开始......

知道如何解决这个问题吗?

【问题讨论】:

  • info.plistUISupportedInterfaceOrientations 设置是什么?
  • 我在 info.plist 中添加了 Supported Interface Orientations 的所有项目。第一个是 Portrait(底部主页按钮)

标签: objective-c cocoa-touch xcode ipad orientation


【解决方案1】:

好的。所以文档说viewWillAppear: 在所有动画之前被调用。当你的应用启动时,它的初始方向是Portrait。根据您的方向,然后它会旋转到该方向。由于它动画到屏幕外的方向,因此必须在viewWillAppear:/ 之后调用它所以当viewWillAppear: 被调用时,它仍然在Portrait 中。我自己测试过。

【讨论】:

    【解决方案2】:

    我解决了这个问题!

    只需在我所有视图的 viewWillAppear 方法中使用它,以使其在以横向模式启动时工作:

    if(([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeRight)){        
        //Landscape View
    }
    else{
        //Portrait View
    }
    

    对我来说很好用!

    【讨论】:

      猜你喜欢
      • 2016-05-03
      • 1970-01-01
      • 1970-01-01
      • 2013-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      相关资源
      最近更新 更多