1

我有一个标签栏应用程序,其中我有 3 个不同的视图,每个视图都有自己的视图控制器。

在标签条码中,我有这个来处理旋转。

#import "RotatingTabBarController.h"

@implementation RotatingTabBarController

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
 }
@end

然后在我想根据设备方向旋转的第二个视图控制器中:

// Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

   return YES;
 }

对于我不想旋转的其他两个视图,我设置了这个方法。

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

问题:所以当你旋转设备时,这在视图 1 和视图 3 中工作正常,它们保持在所需的纵向模式。当我在视图 2 中旋转到横向时,视图会按预期进行并旋转到横向。但是,当在视图 2 中处于横向模式时单击视图 1 或视图 3 选项卡时,视图 1 和视图 3 处于横向模式。

即使视图 2 旋转为横向,我也不知道如何强制它们纵向显示。

有人知道怎么做吗?

4

1 回答 1

1

从 2008 年到现在,对此有一个大讨论 [1](请看几页下的评论)——总而言之,它看起来像

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

或者

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

或者

[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

将让您强制它横向 - 当用户以编程方式返回您的横向视图时,您会想要这样做。

[1]横向模式下的 iPhone 应用程序,2008 系统

于 2010-07-02T13:43:26.230 回答