我在我的应用程序中使用了拆分视图 .
当我在iOS 6模拟器中运行我的应用程序时,它根据方向更改旋转并且运行良好但是当我在iOS 5或iOS 5.1模拟器中运行相同的应用程序并且我更改模拟器的方向但是拆分视图不会根据方向更改而更改 .
我还添加了代码
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
-(BOOL)shouldAutorotate
{
return YES;
}
我使用以下代码添加拆分视图 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {return YES; }
主视图和详细视图中的上述方法 .
我使用以下代码添加了拆分视图
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// obj_PageControlViewController = [[PageControlViewController alloc]initWithNibName:@"PageControlViewController-iPad" bundle:nil];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.detailViewController = detailViewController;
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
TabBarAppDelegate *appDelegate = (TabBarAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.window setRootViewController:self.splitViewController];
}
但它不起作用 . 任何人都可以帮助我吗?
2 回答
你说你添加了
shouldAutorotateToInterfaceOrientation:
但你没有说你添加它的位置 . 要在iOS 5.1或更早版本中自动旋转UISplitViewController,必须在拆分视图控制器的两个子视图控制器(主控制器和详细视图控制器)的视图控制器中提供shouldAutorotateToInterfaceOrientation:
.这将起作用,假设拆分视图控制器是应用程序的顶级(根)视图控制器,由Master-Detail模板设置 .
哦,为自己省点麻烦:在
shouldAutorotateToInterfaceOrientation:
,只需返回YES . 在iPad上,您总是想要自动旋转 .在iOS5及以下版本中你应该使用
您上面发布的那个(shouldAutorotate)适用于iOS6