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?
Related
In iOS 11, when the navigation bar is shown (after having been hidden), the entire view below it moves down. How can I stop this from happening?
Nav bar hidden:
Nav bar showing:
set the transparency of navigation to false.
self.navigationController?.navigationBar.isTranslucent = false;
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
I'm trying to hide iOS navigation bar on UITableView scroll but at the same time make sure the status bar has a background color.
I followed https://www.natashatherobot.com/navigation-bar-interactions-ios8/ to hide the status bar:
class QuotesTableViewController: UITableViewController {
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
navigationController?.hidesBarsOnSwipe = true
}
}
As you can see in the video under Hide Bar On Scroll, the status bar loses its background color (or initially it has no color at all). In my app, bar tint color of the navigation bar is originally set to yellow.
What I'm trying to do is similar to how the Facebook app works on iOS. As you scroll, the navigation bar slides off the screen but the status bar has blue background.
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]
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.