I want to show a View - PresentedView
over another view - Background View
using iOS 7. In my app, I am using UITabBArController
, so at runtime I don't know which view would be the background view (could be any of the tab bar items). Below is the structure:
UITabBarController
---> TabItem1 - FirstUIViewController
---> TabItem2 - SecondUIViewController
---> TabItem3 - ThirdUIViewController
Need something Like this:
When app loads, I am on TabItem1 - FirstUIViewController
. When I click on TabItem3
, I want ThirdUIViewController
to appear on Top on FirstUIViewController
and 'FirstUIViewController' should appear in background with no user interaction enabled.
What I did so far:
Since,
UIViewControllers
are added asRelationship Controllers
to appear asTabBar Item
in `UITabBarController, I added a segue from tabbarcontroller to ThridViewController.Changed PresentationStyle for this Segue to UIModalPresentationStyle.CurrentContext and did below modification
func `viewDidLoad()` { super.viewDidLoad() self.performSegue("identifier", sender: self) }
Nothing happens and I just see 'ThridViewController' with white background
I tried manual coding approach:
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) }
No change. New view overrides the previos view. if I add this overlayController.view.backgroundColor = UIColor.clearColor()
, I see half screen black and half containing my new view
Problem Points:
- Where should I write the code to initialize/call ThirdViewController to appear on top of current view?
- How to fix the black screen issue and make it work on iOS 7?
I am using Xcode 7 and running on iOS7. Please help. Working code snippet will be appreciated. Don't post other stack overflow posts as answer, unless code works & you have tried on your own.
UPDATE: - With this approach, I get a black screen
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
}
}