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

发布于 2024-11-09 15:40:25 字数 1292 浏览 3 评论 0原文

我陷入了一个让我发疯的问题! 我有一个以 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.

我检查了这样的方向:

    -(void)viewWillAppear:(BOOL)animated{

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];



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

}

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

我不明白为什么方向在开始时是纵向,... 即使我从景​​观开始......

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

i stuck on a problem that drives me crazy!
I have an iPad application starting with a TabBarViewController. Every Tab has it's own ViewController and nib-file.

To make interface orientation possible I added all orientations to my info.plist and subclassing my TabBarController to set:

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

Every View is autoresized and formatted well for displaying the right Orientation if I rotate the Interface. If I test it in the simulator, everything looks fine and I can rotate between the Orientations.

Now the point that drives me crazy:

If I launch the App in Portrait Mode, all works fine.. but if I launch in Landscape, I get an error and my Interface orientation seems still to be Portrait, while the Simulator is in Landscape Mode!!

The Error:

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.

I checked for Orientation like this:

    -(void)viewWillAppear:(BOOL)animated{

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];



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

}

The Log says it is in "Landscape" Mode if I launch in Landscape, but if I change tab to another it looks terrible because the View is displayed in Portrait mode instead.
On change back to the start-view where i asked for Orientation… the log displays "Portrait"… but the Simulator is still Landscape!

I can't figure out why the Orientation is Portrait on start,…
even if I start in Landscape…

Any idea how to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挽清梦 2024-11-16 15:40:25

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

Ok. So the documentation says viewWillAppear: is called prior to all animations. And when your app starts, its initial orientation is Portrait. Based on what your orientation is, it then rotates to that orientation. Since it animates to the orientation off screen, this must be called after viewWillAppear:/ So when viewWillAppear: is called, its still in Portrait. I tested this myself.

寂寞陪衬 2024-11-16 15:40:25

我解决了问题!

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

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

对我来说效果很好!

I solved the problem!

Simply used this in viewWillAppear method of all my Views, to make it work when started in Landscape mode:

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

Works fine for me!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文