How to make transparent to second View controller using Swift - swift

I have really trouble to make transparent a view controller. I have 2 view controller. and trying to make transparent second view controller.
This is my first view controller.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destViewController : SearchViewController = storyboard.instantiateViewController(withIdentifier: "SearchViewController") as! SearchViewController
destViewController.getSearchTxt = self.tagsData[indexPath.row]
// destViewController.modalPresentationStyle = .currentContext
destViewController.modalPresentationStyle = .overCurrentContext
self.navigationController!.pushViewController(destViewController, animated: true)
this is my second view controller.
self.view.isOpaque = false
self.view.backgroundColor = .clear
black background is displaying instead of trasparent

For UINavigationController displaying .overCurrentContext is impossible. If you want to display it overCurrentContext use present
self.present(destViewController, animated: true)
If pushViewController is really required you can try to save the previous view to image and add it as a subview to the new SearchViewController.view.

Related

My UIViewcontroller is not filling the entire screen?

I have a very simple app with two UIviewcontrollers. I want to dismiss one and present another one. However, when I do this (code below), the second viewcontroller does not fill the screen, instead it hovers over the top one and can easily get dismissed if you swipe from the top down (you can just about see the first viewcontroller at the top)?
VC-1:
#objc private func picksAction(){
print("picks button pressed")
let layout = UICollectionViewFlowLayout()
let viewController = GridPicksCollectionViewController(collectionViewLayout: layout)
let navController = UINavigationController()
navController.pushViewController(viewController, animated: true)
self.present(navController, animated: true) {}
}
Result:
Set modalPresentationStyle to .fullScreen:
navController.modalPresentationStyle = .fullScreen

Present viewcontroller with tabbar

I created UITabBarController programmatically in AppDelegate with 4 view controllers(using .xib). When user tap some button on ViewController (VC-A) it present another VC (VC-B) and covered tabbar. So I want to VC-B has a tabbar on the button.
I tried to add VC-B as a child of tabbarcontroller. I tried to .present(vc) and .show(vc) on both: VC-A and VC-A.TabBarController
Creating controllers in AppDelegate:
let controllers = [tabViewController1,tabViewController2,tabViewController3,tabViewController4]
tabBarController.viewControllers = controllers
window?.rootViewController = tabBarController
presenting in VC-A
self.tabBarController?.present(controller, animated: false, completion: nil)
right click and drag from tabbar controller in storyboard to VC-B. that should create a tab on the bottom of your VC-A and VC-B to go back and forth without having to implement any backend code unless you want to animate
The solution is to embed every VC in navigationController and then add to TabBarController.
let vc1 = ViewController1()
let navController1 = UINavigationController(rootViewController: vc1)
navController.isNavigationBarHidden = true
let controllers = [navController1, navController2, navController3, navController4]
tabBarController.viewControllers = controllers
window?.rootViewController = tabBarController
Then call
self.navigationController?.pushViewController(controller, animated:
true)
To diplay VC with tabbar
I will press the red login button at the bottom of the picture and try to log in.
login button => "로그인"
After that, log in.
let moreVC = self.storyboard?.instantiateViewController(withIdentifier: "MoreViewController") as! MoreViewController
moreVC.definesPresentationContext = true
moreVC.modalPresentationStyle = .fullScreen
let navController = UINavigationController(rootViewController: moreVC)
self.present(navController, animated: true, completion: nil)
If the login proceeds without error, the above code will be called to display the screen when the login is completed.
If the flow proceeds as the code above, this screen appears.
The screen shown is not fullscreen, and the tabbar at the bottom is gone. The screen I want is the screen below.
How can I present a tab bar when presenting the screen?

Why is hidesBottomBarWhenPushed not working when not root view controller?

A view controller is pushed and the bottom tab bar is hidden like so:
let myViewController = self.storyboard?.instantiateViewController(withIdentifier: MyViewController) as! MyViewController
myViewController.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(myViewController, animated: true)
That works fine.
However when I change the root view controller before the push the bottom bar is not hidden.
// Change the root view controller
let firstRootViewController = UIApplication.shared.keyWindow!.rootViewController
UIApplication.shared.keyWindow!.rootViewController = secondRootViewController
// Push view on stack of navigation controller which is a child of firstRootViewController
let myViewController = self.storyboard?.instantiateViewController(withIdentifier: MyViewController) as! MyViewController
myViewController.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(myViewController, animated: true)
// Some more things happen...
// Switch back to previous root view controller
UIApplication.shared.keyWindow!.rootViewController = firstRootViewController
The result is that the navigation controller pushed the myViewController correctly but the bottom bar is visible, as if the parameter hidesBottomBarWhenPushed was ignored.
What's wrong here?
The solution was to not change the root view controller but to only add the view to the keyWindow:
// Add another view on top of all views
UIApplication.shared.keyWindow?.addSubView(self.view)
// Push view on stack of navigation controller which is a child of firstRootViewController
let myViewController = self.storyboard?.instantiateViewController(withIdentifier: MyViewController) as! MyViewController
myViewController.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(myViewController, animated: true)
// Some more things happen...
// Remove topmost view
self.view.removeFromSuperview()

Attempt to present View Controller which is not in window hierarchy

My initial view controller is created from Storyboard. It has a button which adds a UINavigation :
let navigationController = UINavigationController(rootViewController: ListViewController)
self.presentViewController(navigationController, animated: true, completion:nil)
appDelegate.window?.rootViewController = navigationController
ListViewController has a UICollectionView. Tapping on cell (which I subclassed) calls a delegate method back to ListViewController and presents another View with UICollectionView:
let detailedListViewController = DetailedCollectionViewController(collectionViewLayout: UICollectionViewFlowLayout())
self.navigationController?.pushViewController(detailedListViewController, animated: true)
Inside this DetailedCollectionView each cell has a button to show a full-screen SFSafariViewController. So as before, using delegate I'm trying to show it like this:
SFSafariVC = SFSafariViewController(URL: urlToLoad)
SFSafariVC.view.frame = self.view.frame
self.presentViewController(SFSafariVC, animated: true, completion: nil)
By doing so, I can see the SFSafariView working correctly, but I get the message:
Warning: Attempt to present < UIAlertController: 0x7fcd96353e20 > on
< UINavigationController: 0x7fcd948a0600 > whose view is not in the
window hierarchy!
I tried changing self.presentViewController to self.navigationController?.presentViewController but still the same error persists..

[SWIFT]Presenting Modal View Controller with transparency in ios7

Im trying to present a modal view controller in my app with the background transparent, it works for ios8, but for some reason in ios7 the background becomes gray and doesnt show transparency, Ive already set the alpha to the view in storyboard and below is the code Im using:
let storyboard = UIStoryboard(name: "PopUpStoryboard", bundle: nil);
let vc = storyboard.instantiateViewControllerWithIdentifier("PopUpQuestionController") as PopUpQuestionController;
vc.currentEvent = self.currentEvent
vc.questionMode = "text"
self.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
self.presentViewController(vc, animated: true, completion: nil);
the result in ios8:
and the result in ios 7:
anyone can help me with this?