【问题标题】:UISplitViewController doesn't hide masterViewController in landscape modeUISplitViewController 不会在横向模式下隐藏 masterViewController
【发布时间】:2012-08-08 01:06:38
【问题描述】:

注意: 在阅读这个问题之前,请注意我已经阅读了前面的问题,这些问题解释了苹果实现 UISplitViewController 的缺陷以及我应该如何使用开源的“MGSplitViewController”,因为在拆分视图上简单地隐藏主视图控制器并不容易横向模式的控制器。请记住,我仅限于在 iOS 5.1 中使用普通的 UISplitViewController。

现在进入问题:

我有一个拆分视图控制器,左侧有表格视图(主视图),右侧有一个详细视图控制器。我正在使用导航控制器来控制左侧,这是一个转换到另一个表视图(“DataTableViewController”)的表视图。为了隐藏这个左侧,我在详细视图控制器的导航工具栏上放置了一个“隐藏”按钮。当按下隐藏按钮时,我更改了“_hideMaster”属性:

-(IBAction)hidePressed
{
    _hideMaster = !_hideMaster;
    // Must manually reset the delegate back to self in order to force call "shouldHideViewController"
    self.splitViewController.delegate = nil;
    self.spliteViewController.delegate = self;

}

然后在 SplitViewController 委托中自动调用此方法:

// This is called when I change the delegate from nil back to self.
- (BOOL)splitViewController: (UISplitViewController*)svc shouldHideViewController: (UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation 
{
    return _hideMaster;
}

当我调试它时,我可以看到一切都按计划进行,并且当它进入方法splitViewController:shouldHideViewController:inOrientation:时属性具有正确的值

唯一的问题是什么都没有发生。我最左边的表格视图 (DataTableViewController) 没有消失。当我仔细观察时,委托方法中的(UIViewController *)vc 参数不是我要隐藏的表视图控制器,而是与此表视图关联的导航控制器。所以本质上它是在试图隐藏导航控制器——这显然不是我想要的......

如何使自动调用的委托方法 (shouldHideViewController:) 中的 UIViewController 参数调用与该导航控制器关联的最顶层视图控制器? (毕竟我要隐藏DataTableViewController

【问题讨论】:

  • 真的希望能得到这个答案...

标签: ios hide uisplitviewcontroller


【解决方案1】:

这是我的处理方式。如果在返回的路上没有实例化 MasterViewController,可能需要做更多的工作才能重新出现。

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
[[self.splitViewController.viewControllers lastObject] view].frame = self.splitViewController.view.frame;
[UIView commitAnimations];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2020-05-30
    • 1970-01-01
    相关资源
    最近更新 更多