Can't set fully transparent navigation controller on top of tableView - ios

I do know how to make transparent controller:
self.navigationController!.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController!.navigationBar.shadowImage = UIImage()
self.navigationController!.navigationBar.translucent = true
and it works if in storyboard, in selected ViewController I set Adjust Scroll View Insets + Under Top Bar, but then part first row loads of screen. If I disable those two options, First row seems to be in place, but then Navigation Controller is all black.
Any suggestions how to fix it?

You should just be able to hide the Navigation bar for the Navigation Controller.
In the view controller that you want to hide from:
[self.navigationController setNavigationBarHidden:YES animated:YES]

Related

UINavigation bar not getting cleared in swift3 Xcode

I am trying to achieve a transparent navigation bar such that the background image is shown clearly. Currently i have used a base controller class where i have put a code for transparent navigation bar:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = .clear
But currently i am getting the clear navigation bar only on first page. If i push and go to the second controller i can see a empty white space.
See the below images:
First page with cleared navigation bar
Second page with empty white space at the top
Why the navigation bar is not getting transparent? Any ideas?
As Your navigation bar is transparent, it will show your viewcontroller's view background color.
I think, your second page view controller's view background color is White. Thats the reason you are getting white color.
Add Top Constraint to SuperView, Not to TopLayout Guide
change the view background
self.navigationController?.navigationBar.isTranslucent = true
For more detail about isTranslucent read this doc
https://developer.apple.com/documentation/uikit/uinavigationbar/1624928-translucent

UINavigationBar Transition

Currently, I am having an issue with the transition of two navigation bars. The root view has a transparent navigation bar, while the other navigation bar is opaque with a bar tint color. This is what is currently going on:
https://youtu.be/xfpNnjfOMRc. As you can see, the transparent navbar blinks. The transparent nav bar has this line of code: self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default).
To go about solving this issue, I added this block of code to the second view controller (with the bar tint color):
override func willMoveToParentViewController(parent: UIViewController?) {
super.willMoveToParentViewController(parent)
if parent == nil {
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
}
}
Now however, this happens: https://youtu.be/oMLL0v9_9Yc. When the back button is pressed, the nav bar of the second view controller is rendered transparent, solving the issue above. However, this is not the ideal solution. I simply want a smooth transition between the two nav bars. Ideas?

trying to make nav bar clear, and it's black

I am inside a UINavigationController. The UINavigationController has 3 view controllers. The first 2 are tableViewControllers, the last one is a regular view controller, with a PageViewController embedded.
I am using the following code in the third view controller in the stack to make the UINavigationBar clear:
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
I put this code in the third view controller in the stack. That is the view controller with a UIPageViewController embedded. But the nav bar is black. However, when I pop the third controller off the stack and go back to the second, a UITableViewController, the navigation bar there is clear.
I have looked at numerous other questions, here: How to make completely transparent navigation bar in iOS 7 and here: Transparent UINavigationBar in Swift but nothing works.
what am I doing wrong? the 2 lines of code above are the only ones I'm using, but I have also tried the suggestions in the links above, and nothing works. Here is a photo of the black nav bar:
What worked for me, when I was struggling with the same problem, was to subclass the NavigationController, and use this in the viewDidLoad method:
self.navigationBar.translucent = YES;
self.navigationBar.shadowImage = [UIImage new];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
another reason might be that your ViewController doesn't extended under your UINavigationBar, and thats why you see the black part, try setting this in the viewDidLoad of your ViewContorller
self.edgesForExtendedLayout = UIRectEdgeTop;

iOS navigation bar bottom line is missing

I makes the navigation bar completely transparent by adding the following codes in viewWillAppear:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
self.navigationController?.navigationBar.barStyle = UIBarStyle.Black
Before the current view disappear, I reset the navigation bar by doing this in the viewDidDisappear method:
self.navigationController?.navigationBar.setBackgroundImage(nil, forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = nil
but it turns out the little bottom line of the navigation bar is missing, here is the image that shows the normal navigation bar:
but it turns out being like this:
any idea about what is going on? and any solutions?
thanks
it's missing because you set shadow image to nil. To fix this, delete line below :
self.navigationController?.navigationBar.shadowImage = nil
The navigation bar shadow is only visible when the content scroll view is scrolled a certain distance vertically.
The "content scroll view" is the key—it's the first subview in the controller's view. Starting with iOS 15 you can set it but otherwise, it's based on the order of subviews.
This is also the way that the navigation bar determines whether to display a large title below the navigation bar when large title is enabled.
Frustratingly, not only is this concept not documented by Apple, even the new methods they added this year provide no description or any text at all.

alternating between toolbar / tab bar

my app is structured as follow: UITabBarController > UINavigationController > ViewControllerOne > ViewControllerTwo.
the UINavigationBar has at the bottom the tab bar, now when the user navigates into the second view controller, i want to be able to hide the tab bar and replace is with a tool bar. i tried this code:
[self.navigationController.tabBarController.tabBar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];
when i run the app the tab bar is hidden but the toolbar doesn't appear. plus, since the last VC is a table view controller, when i scroll through the cells there is a white gap between the table and the bottom of the view. how can i fix that?
That won't work because when you hide the tab bar like that the subviews won't be adjusted properly (that's why you get the white space). You'll have to use
self.hidesBottomBarWhenPushed = YES;
In your init method or awakeFromNib... and then
[self.navigationController setToolbarHidden:NO animated:YES];
In the viewDidLoad for example.
That way the tab bar controller's view is going to layout correctly it's subviews when you hide the tab bar. Just remember to call self.hidesBottomBarWhenPushed = NO; in your first view controller otherwise the tab bar is still going to be hidden when the second view controller is popped from the navigation stack.
Try to assigning toolbar with appropriate frame and adding it to self.tabBarController.view

Resources