iOS在UISplitView上呈现视图可能吗?

时间:2015-01-25 19:30:48

标签: ios objective-c uisplitviewcontroller

我一直在努力实现特定的视图演示。在我的应用程序中,我使用UISplitViewController来显示菜单及其内容。我希望在整个视图中自定义显示视图,如图所示。

enter image description here

信息视图和调光视图适用于信息内容,并会在设定的时间段后自动关闭。可以通过我的UISPlitViewController.m

完成此操作

我已经尝试了几种方法,但没有达到预期的效果。

  1. 从Splitview创建一个segue到消息视图,并从viewDidLoad / viewDidAppear调用segue:

    [self performSegueWithIdentifier:@"showMessageView" sender:self];
    
  2. 这会在详细视图中加载视图。

    1. 尝试从viewDidAppear:

      中的代码进行实例化
      MessageViewController *messageVC = [self.storyboard instantiateViewControllerWithIdentifier:@"messageView"];
      [self addChildViewController: messageVC];
      [self.view addSubview: messageVC.view];
      [self presentViewController: messageVC animated:YES completion:nil];
      
    2. 这会导致崩溃:

      Application tried to present modally an active controller
      

2 个答案:

答案 0 :(得分:1)

我遇到了类似的问题:一旦灰暗的叠加层完全可见(显示动画已经完成),它背后的UISplitViewController就会消失。

我的诀窍是在创建后直接设置VC的modalPresentationStyleUIModalPresentationOverFullScreen

以下是我的代码:

UIViewController* customShapeController = [self.storyboard instantiateViewControllerWithIdentifier:@"CustomShapeController"];
customShapeController.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:customShapeController animated:YES completion:nil];

这也适用于segues。确保将segue设置为" Present Modally"在你的故事板中。然后在你的细节VC中调用segue:

[self performSegueWithIdentifier:@"CustomDrawingSegue" sender:sender];

然后调用prepareForSegue:,您可以在目标VC上设置modalPresentationStyle属性:

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIViewController *dest = (UIViewController *)segue.destinationViewController;
    dest.modalPresentationStyle = UIModalPresentationOverFullScreen;
}

答案 1 :(得分:0)

[self addChildViewController: messageVC];
[self.view addSubview: messageVC.view];
[self presentViewController: messageVC animated:YES completion:nil];
哇哇哇哇哇你在这里很困惑。您不添加子视图控制器来呈现它。你做其中一个。 (这正是运行时为你拍打的原因。)

我的建议只是提出它。工作良好。请记住从根视图控制器本身出现,以便生成的呈现视图占据整个屏幕。