Create a custom navigation bar like camera roll image picker has it - ios

I have a modally presented view controller which is not in the navigation stack but needs a navigation bar to cancel the selection. The VC is presented by another VC which is a popup (a real one not a fullscreen view). I need a navigation bar in it to present a title and a cancel-button in the upper right hand corner just like the standard camera roll image picker has it.
Here's what I tried so far:
I added the navigation bar manually by dragging it to the view in the storyboard and attached it with constraints. That works great but the problem is that the navigation bar is too small. It doesn't mind the status bar above it so the cancel button and the title are very close (almost overlapping) to the status bar.
Tried to increase the navigation bar's height but apple doesn't allow changing the frames of navigation bars.
Tried push it down a bit with constraints but that results in a white background color for the status bar since the controller has a white background.
Implemented a new navigation controller just for the one view that needs the bar. But that will give me a standard navigation bar with an arrow in the top left corner which doesn't really fit the navigation feeling since the view is presented modally (from the bottom). Also this seems to be a bit much overhead.
What can I do to achieve a camera-roll-like navigation bar?
BTW: I work with swift.
EDIT:
I tried this but setting the height value fails obviously since it's not allowed.
#IBOutlet weak var navigationBar: UINavigationBar!
override func viewDidLoad() {
navigationBar.frame.height = 44.0
}

I actually found a solution to this:
Set the VC as the delegate for the navigation bar
Conform to protocol UIBarPositioningDelegate
Implement
func positionForBar(bar: UIBarPositioning) -> UIBarPosition {
return .TopAttached
}
Push the navigation bar down with constraints by 20p
Voila

Related

How to hide navigation bar on scroll except when at the top of the screen

I have a UIViewController that contains a UICollectionView pinned to all edges of the view. This view controller is inside a UINavigationController.
I want to gradually hide the navigation bar as I scroll down in the collection view. At the point that I have scrolled the distance of the height of the nav bar, the nav bar should be completely hidden. If I scroll back up it should gradually show the nav bar.
I have tried all the open source navigation bars on github, but none of them work correctly with iOS 12.
How can I achieve this?
UICollectionView is a subclass of UIScrollView and therefore you have access to its scrollViewDidScroll delegate method. Your UIViewController is also owned by its navigation controller, so you can create an instance property in the view controller, like navigationDelegate: UINavigationController?, that will act as a delegate. In the navigation controller, set that property equal to self and manipulate the nav bar however you want through the scroll delegate. Absolutely no need for third-party scripting for something this standard and basic.

iOS top bar not showing

I am trying to show a top bar in Xcode 9 Swift 4. In my storyboard it shows the top bar as in the below picture:
but when I run it I get this with no top bar:
I tried to use a navigation bar just with a title but it shows as:
the carrier, wifi, time, and battery background is still white. If I set the navigation bar to the top of the screen, it will cover them like:
Why the top bar is not showing? How can achieve something like this?:
UPDATE
Top bar is not a navigation bar. It is kind of just a bar that shows a title. As you can see in the below picture, the register scene doesn't have a navigation bar. I added the top bar from the properties on the right side.
In your second to last screen, where you show that the navigation bar covers it:
It does not really cover it - but the text of the status bar is black, so you cannot see it. To change it, in the implementation of the GrolocationNewsViewController (or whatever you call it) override preferredStatusBarStyle and return .lightContent:
class GrolocationNewsViewController: UIViewController {
// rest of the code
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}
}
I have used the code from #Milan Nosáľ answer and it does show the status in white. Then used #Ameya Vichare answer on this link while I was looking for a way to increase the navigation bar height
How to change navigationBar height in iOS 11? turn out it is a bug in Xcode 9. Now it shows like what I wanted:

Change location of Navigation Bar

When using the Navigation Controller it creates a new Navigation Bar on my first view controller. Intead of that bar being at the top of my screen I would like it to be on bottom. Is this possible? If not can I switch to using a different Nav Bar?
Navigation Bars are always at the top of view controllers, and cannot be moved. You could explore a TabBar or ToolBar though, depending on what you want.
Navigation Bar always appear on the top of your UIViewController when embedded in a UINavigationController. You cannot move it to any other position.
Still if you want to achieve such a requirement,
Hide the default UINavigationBar
self.navigationController?.navigationBar.isHidden = true
Create a custom UIView of same height(44) as the UINavigationBar and pin it to the bottom of your controller.

Implementing Navigation-bar and an Extension view attached to the bottom of nav-bar

What's the right way to implement a hides-on-scroll navigation bar along with an extension view attached to the navigation bar's bottom. And on scroll the navigation bar gets hidden and the extension view sticks to the status bar.
You can use TLYShyNavBar library to implement this feature if you want extension view to stick to status bar. If you just want navigationBar to hide along with extension then use hidesBarsOnSwipe property
navigationController?.hidesBarsOnSwipe = true
refer this thread to read more about this behaviour.

How to contain UIViewController view between navigation bar and tab bar?

I have created a storyboard layout which contains UIViewControllers within UINavigationControllers which all connect back to a UITabBarController. There is a login page which is not connected to anything (just a UIViewController) which segues into the UITabBarController when the app detects user authentication. You can see what this looks like in the following image:
When I set the translucent property of the Navigation Bar to "false" or "No", the view y origin gets pushed down to the bottom of the Navigation Bar (which is the behavior that I am looking for). However, when I set the translucent property of the Tab Bar to "false" or "No", the Tab Bar DOES become opaque, but the view is not resized to fit between the top and bottom bars. I have unchecked the Extend Edges property for both Under Top Bars and Under Bottom Bars for all UIViewControllers, UINavigationControllers, and the UITabBarController.
When I add subviews programmatically (no auto-layout), the UIViewController's view is still the height of the entire screen, and is only pushed down from the top bar, but not pushed up from the bottom bar. While creating this question, this is the result I got on the simulator (subviews are not even starting below the Navigation Bar):
The layout that I'm trying to achieve is to have the view fit between the Navigation Bar and the Tab Bar so that both bars are opaque and no content goes underneath them. Any ideas or suggestions?
EDIT:
After eliminating individual Navigation Controllers and adding a single one before the TabBar Controller, I'm getting weird behavior including navigation items disappearing and one of my subviews still goes under bottom bar.
EDIT 2:
After doing some research, It seems that having navigation controllers inside each tab is a normal view hierarchy. Unfortunately, I still have not figured out how to limit a view controller's view to be between a navigation bar and a tab bar. Any suggestions?

Resources