我有spliteview项目并强制它以横向模式。 在我将iOS SDK升级到iOS6之前,它工作正常。 但升级后,当我使用iOS 5.1模拟器运行时,它总是以纵向模式显示,主视图不见了。
这是我的代码:
- (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时,它的原始方向是肖像。 / p>
这里我改变了我的代码:
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];
答案 0 :(得分:0)
尝试添加在iOS 6中添加的新委托方法
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (void)shouldAutorotate {
return NO;
}