【问题标题】:iPad's UISplitViewController did not rotate well when modalView is rotatediPad的UISplitViewController在modalView旋转时没有很好的旋转
【发布时间】:2011-08-27 04:47:30
【问题描述】:

我在UISplitViewController 上遇到了轮换问题。在我的例子中,在splitViewController(这个 splitViewController 是窗口的根视图)上调用 present modal 之后显示另一个视图。当 modalView 旋转时,splitView 旋转不正确。

splitView 看起来像是旋转的,但 DetailViewController 保持在纵向上的样子,而 RootViewController 根本没有显示。它仍然像在纵向模式下一样。似乎 splitView 旋转了,但底层视图没有旋转(DetailViewControllerRootViewController)。

我尝试在modalView上实现willRotateToInterfaceOrientation,并使用委托调用splitView的willRotateToInterfaceOrientation方法。

这是我在modalView中实现的:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    MacProjectAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
    [delegate.splitViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

结果是,DetailViewController 行为正确,但 RootViewController 不正确。它保持隐藏。用户手动旋转为纵向并返回横向后,它将重新出现。但显然用户不希望这样。

这是我在展示 modalView 时所做的:

ModalViewController *modalView = [[ModalViewController alloc] init];
MacProjectAppDelegate *delegate = (MacProjectAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.splitViewController presentModalViewController:modalView animated:YES];
[modalView release];

在这种情况下有没有办法显示RootViewController?还是我做事不对?

编辑: 似乎所有视图都没有跟随 modalView 旋转。 RootViewController 和 DetailViewController 都没有旋转(两个 ViewController 上的the didRotateFromOrientation 根本没有调用)。所以现在我假设它没有跟随 device/modalView 旋转。

【问题讨论】:

  • 您是否尝试过从DetailViewController 而不是直接从 UISplitView 展示您的 modalViewController?
  • 我试过了,但它不起作用。到目前为止,我锻炼的解决方案是获取appDelegate 并让splitViewController 调用willRotateToInterfaceOrientation 两次。一个在modalViewwillRotateToInterfaceOrientation 方法,一个在RootViewControllerwillAppear 方法。但是这种方法还是有问题的。 The DetailViewController 仍然显示导航按钮,就像它处于纵向模式时一样。我还在做这个。
  • 我遇到了同样的问题。在这里查看我的解决方案stackoverflow.com/questions/7767302/…

标签: ipad rotation uisplitviewcontroller


【解决方案1】:

好的。我的问题已经解决了。 我所做的就像我对 Shurakov 的评论所写的评论一样。

我获取 appDelegate 并让 splitViewController 调用 willRotateToInterfaceOrientation。

MacProjectAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.splitViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

我做了两次,因为其中只有一个似乎不起作用(我不知道为什么)。一个在modalViewControllerwillRotateToInterfaceOrientation 方法,一个在RootViewControllerwillAppear 方法。

要删除DetailViewController 上的导航器/弹出框按钮,我只需通过在RootViewControllerwillAppear 方法中调用invalidateRootPopoverButtonItem 来使该按钮无效。这就是这个特定方法的样子(对于modalViewController 的第一个方法,我只是将willRotateToOrientation 命令传递给splitViewController):

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (UIInterfaceOrientationIsLandscape(orientation)) {
    MacProjectAppDelegate *delegate = (MacProjectAppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate.splitViewController willRotateToInterfaceOrientation:orientation duration:1];
    [[[delegate.splitViewController viewControllers] objectAtIndex:1] invalidateRootPopoverButtonItem:self.rootPopoverButtonItem];        
}

希望这可以解释我如何克服我的问题并帮助与我有同样问题的任何人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-26
    • 1970-01-01
    • 2014-12-18
    相关资源
    最近更新 更多