【问题标题】:How to Present a Modal above a View that was added to keyWindow?如何在添加到 keyWindow 的视图上方显示模式?
【发布时间】:2016-03-07 22:05:02
【问题描述】:

我向[[UIApplication sharedApplication] keyWindow] 添加了一个视图,因为我们希望它与导航栏重叠。

现在我们想要点击视图上的一个按钮并以模态方式打开一个窗口,最好使用presentViewController。有没有办法让这个模态视图出现在 keyWindow 视图上方(在 z 轴上)?

我的答案

我最终将我的第一个自定义 UIViewController 添加到 self.tabBarController。这允许UIViewController 与导航栏和标签栏重叠。

然后我使用[self.navigationController presentViewController:animated:completion] 来呈现模态,它高于 z 轴上的一切。

这是将UIViewController 添加到self.tabBarController 的代码

        MyCustomViewController * overlayView = [[MyCustomViewController alloc]
                      initWithNibName:@"MyCustom"
                      bundle:nil];

        UIViewController *parentViewController = self.tabBarController;
        [modalView willMoveToParentViewController:parentViewController];

        // set the frame for the overlayView
        overlayView.view.frame = parentViewController.view.frame;

        [parentViewController.view addSubview: overlayView.view];

        [parentViewController.view needsUpdateConstraints];
        [parentViewController.view layoutIfNeeded];

        // Finish adding the overlayView as a Child View Controller
        [parentViewController addChildViewController: overlayView];
        [overlayView didMoveToParentViewController:parentViewController];

【问题讨论】:

    标签: ios objective-c modalviewcontroller keywindow


    【解决方案1】:

    您应该重新考虑添加覆盖视图的方式。

    如果您希望视图与导航栏重叠,您可以将此视图添加为导航栏的顶部子视图。或者您可以将其添加为导航控制器视图的顶部子视图。

    【讨论】:

    • 抱歉,您能详细说明一下吗?当我查找诸如“导航控制器视图”或“顶部子视图”之类的术语时,我没有找到任何信息。我发现几乎所有关于在Navigation Bar 上放置UIViewController 的东西都说使用keyWindow。 stackoverflow.com/questions/21850436/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 2012-03-30
    • 1970-01-01
    • 2020-01-05
    相关资源
    最近更新 更多