3

我有 spliteview 项目并在横向模式下强制它。在我将我的 iOS SDK 升级到 iOS6 之前它工作正常。但是升级后,当我使用 iOS 5.1 Simulator 运行时,它总是以纵向模式显示,并且主视图消失了。

这是我的代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    MasterViewController *masterViewController = [[[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil] autorelease];
    UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:masterViewController] autorelease];

    CustomverDetailViewController *custView = [[[CustomverDetailViewController alloc] initWithNibName:@"CustomverDetailViewController" bundle:nil] autorelease];

    self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
    self.splitViewController.viewControllers = @[masterNavigationController, custView];


    self.window.rootViewController = self.splitViewController;

    [self.window makeKeyAndVisible];
}

有任何想法吗?

我尝试为不同的版本提供不同的代码,在 iOS6 中似乎还可以,但在 iOS5.1 中,当我进入这个视图时仍然会改变方向,我想当我分配一个新的 UIWindow 时,它的原始方向是纵向的。

在这里我改变了我的代码:

self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

left = [[[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil] autorelease];
UINavigationController *masterNavigationController = [[[UINavigationController alloc] initWithRootViewController:left] autorelease];


right = [[CustomverDetailViewController alloc] initWithNibName:@"CustomverDetailViewController" bundle:nil];


self.splitViewController = [[[UISplitViewController alloc] init] autorelease];
self.splitViewController.viewControllers = @[masterNavigationController, right];


if (([[[UIDevice currentDevice] systemVersion] floatValue ] < 6.0 )) {


    self.splitViewController.delegate = left;
    [self.splitViewController.view setFrame:CGRectMake(0, 0, 1024.0f, 768.0f)];

    self.window.rootViewController = self.splitViewController;
     [self.window makeKeyAndVisible];


}else{
    self.window.rootViewController = self.splitViewController;
    [self.window makeKeyAndVisible];
}

[right release];

在 iOS 6 在 iOS 5.1 中

4

1 回答 1

0

尝试添加在 iOS 6 中添加的新委托方法

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

- (void)shouldAutorotate {
    return NO;
}
于 2012-10-17T09:42:49.720 回答