gpt4 book ai didi

swift - 当 View Controller 从 nib 文件获取负载时,在当前上下文中以模态方式呈现 View Controller

转载 作者:行者123 更新时间:2023-11-30 10:33:39 25 4
gpt4 key购买 nike

我需要通过从 Storyboard加载的现有 View Controller A 来呈现从 xib 文件加载的 View Controller B。

如果我从 Storyboard加载 View Controller B,它会正常工作,并将在 View Controller A 的当前上下文中呈现,但如果我从 nib 文件加载它,它将不会在当前上下文中呈现。

从 Nib 加载:

let vc = ViewControllerB()
vc.modalTransitionStyle = .crossDissolve
vc.modalPresentationStyle = .overCurrentContext
present(vc, animated: true, completion: nil)

从 Storyboard加载:

let vc: ViewControllerB = ViewControllerB.instantiate()
let navigationController = UINavigationController(rootViewController: vc)
navigationController.setNavigationBarHidden(true, animated: false)
navigationController.modalPresentationStyle = .overCurrentContext
(tabBarController as? TabBarController)?.present(navigationController, animated: true, completion: nil)

TabBarController 是我的自定义 Controller 。

如果我从 xib 文件加载它, View Controller B 完全呈现在 View Controller A 的顶部,以便呈现样式不会超过当前上下文,我希望仍然可以看到下面的 View 或 View Controller A。有很多这里有相关的帖子,但没有一个提到在当前 View Controller 上下文上呈现由 xib 文件创建的 View Controller 。

最佳答案

通过 Storyboard或 nib 文件加载 View 对于在当前上下文中以模态方式呈现 View 没有任何区别,在我的情况下,我将父 Controller 的背景颜色更改为在子 Controller 顶部可见。

关于swift - 当 View Controller 从 nib 文件获取负载时,在当前上下文中以模态方式呈现 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58561634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com