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
Related
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.
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
I have added MMDrawerController to my project,before using MMDrawerController the navigation bar was appearing as desired in black color and the bar button item was also visible but when I added MMDrawerController to the project ,the navigation bar shows grey color rather than showing black and the bar button item also doesn't come .Kindly help me to get the navigation bar in black color and bar button item also visible.Thanks in advance!
//MARK: function for adding MMDrawer controller
func buildNavigationDrawerInterface () {
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let centerVC = mainStoryBoard.instantiateViewController(withIdentifier: "tabbar") as!UITabBarController
centerVC.tabBar.barTintColor = UIColor.black
let leftVCs = mainStoryBoard.instantiateViewController(withIdentifier: "LeftViewController") as! LeftViewController
let leftSideNav = UINavigationController(rootViewController: leftVCs)
let centerSideNav = UINavigationController(rootViewController: centerVC)
drawerContainer = MMDrawerController(center: centerSideNav, leftDrawerViewController: leftSideNav)
drawerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.panningCenterView
drawerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.panningCenterView
//centerContainer?.setDrawerVisualStateBlock(MMDrawerVisualState.swingingDoorVisualStateBlock())
window!.rootViewController = drawerContainer
window!.makeKeyAndVisible()
}
I want to create an app that lets the user click on a button on V1 on the navigation bar. This will segue to V2 where they can press another button on the navigation bar on V2 and it will bring them back to V1 which has the tab bar controller at the bottom. I don't want the tab bar on V2 and I don't want V2 as a tab bar item. When I try this the tab bar disappears on V1 when I segue back to V1 from V2.
TAB BAR CONTROLLER -> TAB BAR ITEM (V1) -> V2(Via navigation bar button item on V1) -> back to V1(Via navigation bar button item on V2)
I have added [self.navigationController, popViewControllerAnimated:YES]; to my button function but it comes up with an error - expected expression in container literal.
Apart from this code I have not got any other code in my app yet.
I am using Xcode 8.0 and Swift 3.0
First create subclass of UITabBarController, Then add properties to AppDelegate
var navController: UINavigationController?
var tabController: MyTabController?
If you want to show tab bar controller on app launch then put these code in AppDelegate in didFinishLaunchingWithOptions
self.window = UIWindow(frame: UIScreen.main.bounds)
let myStoryboard = UIStoryboard(name: "Main", bundle: nil) as UIStoryboard
self.tabController = myStoryboard.instantiateViewController(withIdentifier: "MyTabController") as? MyTabController
//self.navController = UINavigationController(rootViewController: self.tabController!)
//self.window?.rootViewController = self.navController
self.window?.rootViewController = self.tabController
self.window?.makeKeyAndVisible()
return true
If you want to jump on tab bar after login or something else then , add property to that controller
var appDelegate: AppDelegate!
in viewDidLoad
appDelegate = UIApplication.shared.delegate as? AppDelegate
And method should like
func logIntoApp() {
appDelegate.tabController = self.storyboard?.instantiateViewController(withIdentifier: "MyTabController") as? MyTabController
appDelegate.window?.rootViewController = appDelegate.tabController
}
Then in your tab item view controller , create property of AppDelegate and assign delegate as above.
And methods should be like :
#IBAction func showWithTab(_sender: AnyObject) {
let DefaultVC = self.storyboard?.instantiateViewController(withIdentifier: "DefaultViewController") as! DefaultViewController
self.navigationController?.pushViewController(DefaultVC, animated: true)
}
#IBAction func showWithoutTab(_sender: AnyObject) {
let DefaultVC = self.storyboard?.instantiateViewController(withIdentifier: "DefaultViewController") as! DefaultViewController
// You can create your own animation
UIView.transition(from: (appDelegate.tabController?.view)!, to: (appDelegate.navController?.view)!, duration: 0.3, options: UIViewAnimationOptions.curveEaseIn) { (finished) in
self.appDelegate.window?.rootViewController = self.appDelegate.navController
}
// OR you can use like this way
UIView.transition(from: self.view, to: DefaultVC.view, duration: 0.3, options: UIViewAnimationOptions.curveEaseIn) { (finished) in
self.appDelegate.window?.rootViewController = self.appDelegate.navController
}
}
Why not use a simple Tab Bar?
Something like this:
and in VC1 :
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
myTab.removeFromSuperview()
}
I have solved my problem after days of trying to figure out an answer. You need to add this to any view controller.
#IBAction func unwindToViewController (sender: UIStoryboardSegue){
}
Then you can add a segue from bar button item to the exit icon on the view controller.
You can view an image of the VC scene here.