我正在尝试实现一个导航栏,其内容在不同的 View Controller 之间保持不变。例如,我现在有以下功能:
我已经设置了一个 imageView 作为导航栏的 titleView。
导航栏的 titleView 随 View Controller 一起转换(图像通过淡入和淡出显示一些动画)。但我希望它在没有任何过渡的情况下保持卡在每个屏幕的顶部。这意味着只有导航栏下方的 View 部分会显示从一个 View Controller 到另一个 View Controller 的转换。
这在 Swift 中可能吗?
最佳答案
是的,这是可能的。您可以做的是拥有一个容器 View Controller ,它可以包含您的导航栏和一个内容 View Controller 。
现在每次打开一个新的 VC 时,将新的 VC 推送到 containerVC 的 contentVC 上。
例如:
let containerVC = self.parentViewController?.containerViewController()
if let _ = containerVC {
containerVC.pushContentViewController(newViewController)
}
附上布局截图以供更多理解。
因此,如果您在此处选中,根容器是您可以将新 VC 添加为子 VC 的 View 。
关于ios - 不同 View Controller 的固定导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48606187/