我想使用 iOS 7 显示一个视图 -PresentedView
在另一个视图Background View
上。在我的应用程序中,我正在使用UITabBArController
,所以在运行时我不知道哪个视图将是背景视图(可能是任何标签栏项目)。下面是结构:
UITabBarController
---> TabItem1 - FirstUIViewController
---> TabItem2 - SecondUIViewController
---> TabItem3 - ThirdUIViewController
需要这样的东西:
当应用程序加载时,我在TabItem1 - FirstUIViewController
. 当我点击 时TabItem3
,我想出ThirdUIViewController
现在 Top onFirstUIViewController
并且“FirstUIViewController”应该出现在背景中,并且没有启用用户交互。
到目前为止我做了什么:
由于
UIViewControllers
添加为Relationship Controllers
在TabBar Item
`UITabBarController 中显示,我添加了一个从 tabbarcontroller 到 ThridViewController 的 segue。将此 Segue 的 PresentationStyle 更改为 UIModalPresentationStyle.CurrentContext 并进行了以下修改
func `viewDidLoad()` { super.viewDidLoad() self.performSegue("identifier", sender: self) }
什么也没发生,我只看到白色背景的“ThridViewController”
我尝试了手动编码方法:
func `viewDidLoad()` { super.viewDidLoad() let overlayController:UIThirdViewController = UIThirdViewController() //This controller has a view added on top of it, which covers top half screen only overlayController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext self.presentViewController(overlayController, animated: true, completion: nil) }
不用找了。新视图会覆盖之前的视图。如果我添加这个overlayController.view.backgroundColor = UIColor.clearColor()
,我会看到一半是黑色的,一半是包含我的新视图的
问题点:
- 我应该在哪里编写代码来初始化/调用 ThirdViewController 以显示在当前视图的顶部?
- 如何修复黑屏问题并使其在 iOS 7 上运行?
我正在使用 Xcode 7 并在 iOS7 上运行。请帮忙。工作代码片段将不胜感激。不要发布其他堆栈溢出帖子作为答案,除非代码有效并且您自己尝试过。
更新: - 使用这种方法,我得到一个黑屏
class TabBarViewController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
let switchController:UIViewController = SwitchViewController()
self.presentingViewController?.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
self.presentingViewController?.view.backgroundColor = UIColor.clearColor()
self.presentViewController(switchController, animated: true, completion: nil)
return false
}
}