white space on top of UITabBarController - swift

i can't get rid of white space on top of my view. This only happens when I want to use navigation controller.
let viewController = ViewController()
let navController = UINavigationController(rootViewController: viewController)
self.present(navController, animated: true, completion: nil)

In your navController, add the following line in the viewWillAppear method.
navC.setNavigationBarHidden(true, animated: false)
A navigation controller adds a navigation bar by default on all its child view controllers. If you want the navigation bar to be hidden. We need to do it explicitly in each child view controller.

If you use Storyboard: Attribute Inspector > uncheck Adjust Scroll View Inset.
Or set programmatically:
self.automaticallyAdjustsScrollViewInsets = false

Related

Swift How can I add Navigation Controller after creating Views

I created View Controllers and I want to add Navigation Controller now. I tried embed-in Navigation Controller to My DetailViewContoller(colorful View Controller) but I got an error. main.storyboard, error. How can I add Navigation Controller ?
In order to set view controller as navigation controller, you can set it programmatically by calling this function in appdelegate or scenedelegate or any point.
func setNavigationController() {
var viewController: UIViewController
let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "myVCID")
let rootViewController = UINavigationController(rootViewController: viewController)
rootViewController.setNavigationBarHidden(true, animated: false)
self.view.window?.rootViewController = rootViewController
}
If you want to set navigation controller through storyboard, then you have to first add navigation controller and set is root view controller to the controller you want to make it navigation controller.

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?

Segue To Navigation Controller in Tab Bar Controller

In my application, I have a default tab selected for my Tab Bar Controller. On the viewDidLoad() of the default tab, I have this:
if (NSUserDefaults.standardUserDefaults().stringForKey("defaultCode") == nil) {
//let navController:UINavigationController = UINavigationController()
//self.presentViewController(navController, animated: true, completion: nil)
self.tabBarController!.selectedIndex = 1
I thought calling selectedIndex would do what I was looking forever; however, it only changes the selected tab in the TabBar, but my view does not change. The area I commented out quickly shows the proper view, then goes to a black screen. The view I am trying to switch to is a Navigation Controller
selectedIndex always be the first and pop/push after selected

ScrollView and Navigation Bar ios9

I have a View Controller (named View2) embedded in a Navigation Controller.
In this view I have a ScrollView which covers all the view (including the navigation bar).
This View Controller is presented from another view with the call:
let view2 = self.storyboard?.instantiateViewControllerWithIdentifier("View2") as! View2
let modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CrossDissolve
let nav: UINavigationController = UINavigationController.init(rootViewController: view2)
nav.modalTransitionStyle = modalStyle
self.presentViewController(nav, animated: true, completion: nil)
In my View2, I adjust the navigation bar to be translucent:
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.translucent = true
But there is an issue, when View2 appears, the scrollview starts bellow the navigation bar. I have to tapp one time on the scrollview to see it auto-adjust at the top of the screen, over the navigation bar.
Any idea to fix it?
I want than the scrollview appears at the top of the screen, over the translucent navigation bar.
Thank you for your feedbacks,
Thomas
Did you try setting automaticallyAdjustsScrollViewInsets = false on your view controller?
Another option would be to uncheck the option "Under Top Bar" in the view controller's attributes inspector in "Extend Edges".
Hope this helps.

How to present a view controller inside a navigation controller SWIFT

I have VC1 which is a basic view controller, I then want to present VC2 which is inside a navigation controller. Whenever I present it, it doesn't display the navigation controller. I want this all done pragmatically. The code I have been using to present VC2 is:
func matchesPressed(sender: UIButton!) {
let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches
self.presentViewController(matchesTVC, animated: true, completion: nil)
}
How do I present the navigation controller it is inside as well?
Is the navigation controller in the storyboard? If so, give it a storyboard ID and replace your matchesTVC stuff with the navigation controller.
If matches is a standalone view controller in the storyboard, you can do it in code like this:
let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches
let navContr = UINavigationController(rootViewController:matchesTVC)
self.presentViewController(navContr, animated: true, completion: nil)
Instantiate the navigation controller that contains your view controller and present the navigation controller.