we have used default tabbarcontroller. Tabbar rootViewController display tabbar and other viewcontroller hidden tabbar.The bottom layout of safearea not update hight when we use interactivePopGesture. All other case its working fine
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if navigationController?.viewControllers[0] == self {
tabBarController?.tabBar.isHidden = false
} else {
tabBarController?.tabBar.isHidden = true
}
}
// issue is in your Tabbar related view controller Properties
Follow Below steps:
1) selected your tabbar prfile viewcontroller
2) disable Hide Bottom bar on Push
3) enable Hide Bottom bar on Push when you push on other view controller
// i was solved this issue like that in appdelegate when iam check user already login then i will remove removeGestureRecognizer from view
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let loginPageView = mainStoryboard.instantiateViewController(withIdentifier: "CustomTabVCID") as! CustomTabVC
let rootViewController = self.window!.rootViewController as! UINavigationController
rootViewController.view.removeGestureRecognizer(rootViewController.interactivePopGestureRecognizer!)
rootViewController.pushViewController(loginPageView, animated: true)
// for bottom bar
// Use this [![enter image description here][1]][1]
// add this line when you navigate to a ViewController hidesBottomBarWhenPushed
let vc = storyboard.instantiateViewController(withIdentifier: VC_IDENTIFIER) as! YourViewController
vc.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(vc, animated: true)
// hope its work for you
or try with Main StoryBoard!
[1]: https://i.stack.imgur.com/IiVrj.png
Related
I have added tab bar controller to my view controller, a white space is visible in the top of my view. I have tried to set my navigation bar visible to false in viewwillappear function, it didn't work. I have unchecked under bar in extended edges, that didn't work either. Someone please guide me through this problem.
My Storyboard
https://i.stack.imgur.com/SxOYH.png
SceneDelegate.swift
guard let winScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: winScene)
let storyboard = UIStoryboard(name: "Home", bundle: nil)
let initialViewController = storyboard.instantiateViewController(identifier: "TabBarController")
let navController = UINavigationController(rootViewController: initialViewController)
window?.rootViewController = navController
window?.makeKeyAndVisible()
HomeVC.swift
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
Click your navigation controller, select attribute inspector at the right side of Xcode. unselect show navigation bar option in the navigation controller section as shown in image
When presenting my viewcontroller this way I don't get a navigationbar, even though the viewcontroller is embedded in a navigation controller in the interface builder.
if let stockVC = storyboard?.instantiateViewController(withIdentifier: "Stock") as? StockTableViewController {
stockVC.stockToDisplay = commonData.stock.filter { $0.productID.contains(product) }
// No NavigationBar with this one
navigationController?.present(stockVC, animated: true)
// No NavigationBar with this one
self.present(stockVC, animated: true)
}
I know the navigationBar works, because if I set the ViewController as initial in the storyboard, it shows.
What am I doing wrong here?
When you present a view controller, it is not part of the current navigation stack. You need to create a new navigation controller with your stockVC contained in it, and present the new navigation controller:
if let stockVC = storyboard?.instantiateViewController(withIdentifier: "Stock") as? StockTableViewController {
stockVC.stockToDisplay = commonData.stock.filter { $0.productID.contains(product) }
let stockNavigationController = UINavigationController(rootViewController: stockVC)
self.present(stockNavigationController, animated: true)
}
I've following view configuration
Tab bar -> Nav controller -> View: Click on a button -> segue to-> Another view: Click on a button -> Popup view.
This modal view is on a different storyboard.
I want to present this model view in full screen. I've tried this solution mentioned on Presenting modal in iOS 13 fullscreen but it doesn't work. I've also tried few other solutions but the popup view is not showing over full screen, status bar is visible at the top.
How do I present modal view in a full screen?
let storyboard = UIStoryboard(name: "Other", bundle: Bundle.main)
guard let popupVC = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as? PopUpViewController else {
print("PopUpViewController not found")
return
}
popupVC.modalPresentationStyle = .fullScreen
self.present(popupVC, animated: true, completion: nil)
You could try presenting with the navigation controller.
let storyboard = UIStoryboard(name: "Other", bundle: Bundle.main)
guard let popupVC = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as? PopUpViewController else {
print("PopUpViewController not found")
return
}
var navigationController = UINavigationController(rootViewController: popupVC)
navigationController.modalPresentationStyle = .fullScreen
self.present(navigationViewController, animated: true, completion: nil)
An alternative would be to use presentViewController but presentViewController will only present one viewController modally over the currently visible viewController whereas presenting with the navigationController will give the flexibility to push further components on top, providing a smoother navigation experience with go back to previous page kind of behaviour.
Maybe try creating the view controller this way:
let popOverVC = UIStoryboard(name: "yourBoard", bundle: nil).instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
self.addChild(popOverVC)
let lSs = UIScreen.main.bounds
popOverVC.view.frame = CGRect(x: 0, y: 0, width: lSs.width, height: lSs.height)
popOverVC.view.tag = tag
self.view.addSubview(popOverVC.view)
popOverVC.didMove(toParent: self)
Within the popup view controller class, add a method for animating its view in viewDidLoad.
Edit: I read your replies. The issue you are having is caused by not handling the status bar properly. Instead of trying to make this veiewcontroller fullscreen, simply hide the status bar
How do I hide the status bar in a Swift iOS app?
and bring it back when you want to see it again.
I tried same code mention in gist : https://gist.github.com/barbietunnie/e5547f35180436ac102cac52a15f8ca3
func showModal() {
let modalViewController = ModalViewController()
modalViewController.modalPresentationStyle = .OverCurrentContext
presentViewController(modalViewController, animated: true, completion: nil)
}
class ModalViewController: UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.clearColor()
view.opaque = false
}
}
Its working fine but in case of tab bar the content is getting beyond tab bar, How can we make content visible upper/front of tab bar?
It worked via vc.modalPresentationStyle = .overFullScreen
I hope it will work for you,
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let controller = mainStoryboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
controller.modalPresentationStyle = .overCurrentContext
Thank You.
I was able to create an iOS application in which you could switch between views with buttons. These views had a navigation controller so you could go back.
However I want to adapt this slightly.
Instead I want to have a single view start with no navigation controller.
Then when a cell in my table view is clicked, I want to navigate to the next view which has a navigation controller.
I can make this happen using segue in the interface builder but I don't want to manage it through the builder. This is because I only want to go to the next view when I have done some checking on the cell clicked in the table view.
So basically I need to programmatically change views.
Here is what I have done so far:
I have an ordinary View Controller.
I then have next to it a Navigation Controller which is linked to a new View Controller after that.
I gave this View a storyboard ID of presetController.
I then have the below code in my table cell onclick function:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "presetController") as! PresetNavigationController
self.present(nextViewController, animated:true, completion:nil)
Now this code takes me to the next view, but no navigation controller is loaded.
How can I make the navigation controller link to this view? It already is embedded to it via the editor tab link.
Photo to explain story board:
StoryBoard
You need to swap View Controller with Navigation Controller and then do this code:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "presetController") as! PresetNavigationController
self.present(nextViewController, animated:true, completion:nil)
this will make your navigationbar back button appear
If your link Navigation controller from New controller and Your are opening presntview controller than you will be make as this
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "presetController") as! PresetNavigationController
let navController = UINavigationController(rootViewController: nextViewController)
self.present(navController, animated:true, completion: nil)
Using the suggestions from ppinho I put the navigation controller as the entry point.
As I did not want the navigation controller on the first view I hid it with the below code:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Hide the navigation bar on the this view controller
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Show the navigation bar on other view controllers
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}
I then added the new view to the navigation like so:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "presetController") as! PresetViewController
self.navigationController?.pushViewController(nextViewController, animated: true)
Here it is
let nextScreen = storyboard?.instantiateViewController(withIdentifier: "nextScreenIdentifier") as! NextScreenControllerName
self.navigationController?.pushViewController(nextScreen, animated: true)
write this inside any function of the viewcontroller.