2

我已经搜索了这个论坛(和其他),但还没有找到解决方案。我有一个横向模式的应用程序。一切都很好,但是当我更改为另一个视图(使用 UITable)时,它处于纵向模式并且不会旋转。我已经尝试了一整天,但无法弄清楚。

@property (nonatomic, strong) IBOutlet UIView *aView;
@property (nonatomic, strong) IBOutlet UIViewController *aViewcontroller;
-----
aViewcontroller = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
aViewcontroller.view = aView;
-----
[self presentModalViewController:aViewcontroller animated:YES];
//got my view in portrait orientation.

我的 .xib 文件中的视图都设置为 Orientation:Landscape。这应该很简单吧?

预先感谢!

4

1 回答 1

2

默认情况下 UIViewController 只支持纵向。为了支持其他方向,您需要创建新的自定义视图控制器来支持您需要的方向。

脚步:

创建新的自定义视图控制器ViewControllerLandscape

然后将其导入您的 mainn 视图控制器

#import "ViewControllerLandscape.h"

更改您的代码:

aViewcontroller = [[ViewControllerLandscape alloc] initWithNibName:@"ViewController" bundle:nil];
aViewcontroller.view = aView;
[self presentModalViewController:aViewcontroller animated:YES];

在你ViewControllerLandscape添加方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
      (interfaceOrientation == UIInterfaceOrientationLandscapeRight))  {   
       return YES;
    }
    return NO;
}
于 2012-07-26T13:43:10.397 回答