ios - UISplitview 方向在 iOS 5 和 iOS 5.1 中没有改变

标签 ios uisplitviewcontroller uiinterfaceorientation

我在我的应用程序中使用了分割 View 。
当我在 iOS 6 模拟器中运行我的应用程序时,它会根据方向变化进行旋转并且运行良好,但是当我在 iOS 5 或 iOS 5.1 模拟器中运行相同的应用程序时,我会更改模拟器的方向,但 Split View不会根据方向变化而变化。
我还添加了代码

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(BOOL)shouldAutorotate
{
    return YES;
}

我使用以下代码添加分割 View - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)界面方向 { 返回是; }

在主视图和详细 View 中都可以使用上述方法。

我使用以下代码添加了分割 View

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];

}

但这不起作用。任何人都可以帮助我吗?

最佳答案

您说您添加了 shouldAutorotateToInterfaceOrientation:,但您没有说您添加它的位置。要在 iOS 5.1 或更早版本中获得 UISplitViewController 的自动旋转,您必须在分割 View Controller 的两个 subview Controller (主视图 Controller 和主视图 Controller )的 View Controller 中提供 shouldAutorotateToInterfaceOrientation:详细 View Controller )。

假设分割 View Controller 是应用程序的顶级(根) View Controller (由主从模板设置),这将起作用。

哦,这样可以省去一些麻烦:在 shouldAutorotateToInterfaceOrientation: 中,只需返回 YES 即可。在 iPad 上,您总是希望自动旋转。

关于ios - UISplitview 方向在 iOS 5 和 iOS 5.1 中没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13506469/

相关文章:

ios - 在外部函数中返回内部值函数

ios - 线程 1 : EXC_BAD_ACCESS (code=1, 地址=0xf1759018)

iphone - 如何防止UItable View 的tableHeaderView滚动,粘在顶部

嵌套导航 Controller 上的 iOS8 行为

iOS动画不保持最后位置

ios - 使用 viewWillTransition 更改方向时 UIView.isHidden 不起作用

ios - 在 ios 上旋转时更改 subview

ios - 以编程方式创建的 UITableView 在 iOS9 中始终为白色

ios - XCode 5 中图像的命名约定

swift - 在 UIableView 中设置要突出显示的默认单元格