界面方向不会更改为应用程序启动时的横向

时间:2011-05-24 20:10:11

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

我坚持一个让我疯狂的问题! 我有一个以TabBarViewController开头的iPad应用程序。每个标签都有自己的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.

我检查过Orientation:

    -(void)viewWillAppear:(BOOL)animated{

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];



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

}

Log表示如果我在Landscape中启动它处于“Landscape”模式,但是如果我将tab更改为另一个,它看起来很糟糕,因为View在Portrait模式下显示。 在改变回到我要求定位的开始视图时...日志显示“肖像”......但模拟器仍然是风景!

我无法弄清楚为什么定位是肖像开始,... 即使我从景​​观开始......

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

2 个答案:

答案 0 :(得分:2)

确定。所以文档说在所有动画之前调用viewWillAppear:。当您的应用启动时,其初始方向为Portrait。根据您的方向,然后旋转到该方向。由于它会向屏幕上的方向设置动画,因此必须在viewWillAppear: /之后调用它。因此,当viewWillAppear:被调用时,它仍在Portrait中。我自己测试了这个。

答案 1 :(得分:0)

我解决了这个问题!

在我的所有视图的viewWillAppear方法中使用它,以便在横向模式下启动时使用它:

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

对我来说很好!