Present UINavigationController as modal, status bar issue - ios

I'm trying to present a nav controller (within a vc) as a modal like so:
let myNavController = UINavigationController(rootViewController: someVc)
self.present(myNavController, animated: true)
I'm noticing that it isn't full screen ... the status bar area is black on my 5S device, and on iPhoneX there is similar black space at the top.
It seems like the modal snugs up against the bottom of the status bar's area.
Is there something I need to do to set this space to white? i.e. adjust the status bar style? Extend edge settings?
5S:
iPhoneX:

It seems that the UINavigationController.navigationBar was being set to "transparent"!
self.navigationController?.navigationBar.isTranslucent = false
^ fixed the issue!

Related

Visible UISearchBar changes UINavigationBar background color

A tableview controller is embedded into a navigation controller.
I programmatically added a search bar to the tableview controller's navigation bar. I only changed the navigation bar Background color into something different than Default (purple) - all the rest I left default.
class TableViewController: UITableViewController {
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.hidesSearchBarWhenScrolling = true
navigationItem.searchController = searchController
}
}
Code above is reduced to bare minimum for demonstration purpose.
All done with Xcode 11 (11A420a).
I ran the project in iOS 12.0 and 13.0 simulators and devices.
iOS 13.0
The search bar shows upon start.
Navigation bar background color is correctly presented.
While scrolling, navigation bar background color remains correct.
With iOS 13.0, all works as expected!
iOS 12.0
The search bar doesn't show upon start.
Navigation bar background color is correctly presented.
While scrolling, navigation bar background color goes white as soon search bar is visible.
I tried to change all kind of color setting in storyboard as well as properties programmatically. I didn't succeed in changing the navigation bar background color when search bar is visible.
It seems (?!) that the navigation bar foreground looses transparency when search bar becomes visible.
If I use a Bar Tint color of the navigation bar (!= Default), all works as expected (and as with iOS 13.0), but I loose the gradient effect, which I would like to keep.
What did I miss?
How can I avoid this?
Bug?
I had some luck with the navigationItem.scrollEdgeAppearance property when facing a similar problem. For example:
vc.navigationItem.scrollEdgeAppearance?.backgroundColor = .red
This is only available on iOS 13 though.
Here's what I ended up doing to get correct colors in the navigation bar while allowing the search controller's scroll bar to hide during scroll:
if #available(iOS 13.0, *) {
let blurEffect = UIBlurEffect(style: .systemUltraThinMaterial)
navbar.standardAppearance.backgroundEffect = blurEffect
navbar.standardAppearance.backgroundColor = appMainColor.withAlphaComponent(0.75)
navbar.standardAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor : UIColor.white]
navbar.compactAppearance = nil
navbar.scrollEdgeAppearance = navbar.standardAppearance.copy()
navitem.standardAppearance = nil
navitem.compactAppearance = nil
navitem.scrollEdgeAppearance = nil
}
I don't know if it is the look you're going for but I found if you disable hideSearchBarWhenScrolling the background stops changing color. However, the search bar is always there.
Add this to viewDidLoad():
navigationItem.hidesSearchBarWhenScrolling = false

Status bar left white rectangle after rotate in landscape mode

I have VC with UIView with hidden navigation bar with
self.navigationController?.setNavigationBarHidden(true, animated: animated)
At top VC have my view with constraint View.top = SafeArea.Top
When in portrait mode - all is ok. But when rotate to landscape mode status bar left in VC like white rectangle.
I don't need status bar in landscape. How to remove it? And why statusbar left this rectagle?
I have implemented the code according to your scenario it's working fine for me. I thinks this is problem with xcode/compiler. You can do:
set the main view clipToBounds property to true.
Hide navigation bar from storyboard: Select NavigationController, open identity inspector, untick the shows Navigation Bar option
SORRY!
I find the reason.
This is a custom view, that used for coloring statusbar.
Example of adding this view.
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
let statusBarColor = UIColor(r: 240, g: 243, b: 245)
statusBarView.backgroundColor = statusBarColor
view.addSubview(statusBarView)
Thank you everyone!

How to make view go under navigation bar

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;

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

when navigationBar.isTranslucent is true, the backgroundImage of navigationbar become translucent too

In my first page, the navigation bar should be transparent, and when push to next page, the navigation bar should be a image. I worked it out by changing the _UIBarBackground or _UINavigationBarBackground's alpha.
But I meet a big problem, in the first page, view should be placed and draw from (0,0) so I set the navigation bar's isTranslucent to true, that all works fine. But when I enter the next page, background image shows with a translucent looking which I don't want.
btw, I set background using:
navVC.navigationBar.setBackgroundImage(UIImage(named: "navigation_bar_background"),
for: .default)
I checked the image used here, and it's not translucent.
What can I do with this issue? I don't want set viewController's extendedLayoutIncludesOpaqueBars to true due to ugly appearance when animation.
Combination of these 2 solutions will help.
http://ioscodeguide.blogspot.in/2014/01/navigation-bar-bagground-image.html
http://ioscodeguide.blogspot.in/2014/01/navigation-bar-font-style-and-font.html
In first view:
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
In 2nd view:
Set image to your navigationBar using the following link.
How to set Navigation Bar Bagground image - By - iOSCodeGUIDE
Adding to that
To keep navigation bar transparent in first page and display on 2nd page,
1st Page viewwill appear Hide-Yes NavigationBarHide, and on view did disappear Hide-No

Resources