Swift - how to mimic iOS's Files app expandable navigation bar - ios

I'm working on iOS application in Swift and I'm showing a table views in Navigation Controller with a Navigation bar.
I'd like to implemented the same "Toolbar experience" as the Files app does. (see attached image) in order to present additional options/buttons without cluttering the screen (for UX purposes mostly).
I could not find anything related, expect for workaround with toolbar on top, but it does not work as part of the navigation bar, meaning that after navigation that toolbar is no following the navigation bar but instead stays on the previous controller.
The ideal behavior is:
to expand when scrolling down (requires table view to be scrolled to top) and to collapse when scrolling down.
to keep the toolbar attached to the navigation bar on navigation (push & pop)
In the screenshot, the toolbar is showing additional options (under the search bar). I'd very much like to do the same.

Related

Implementing Safe Areas for Tab Bar Controller and iPhone X

What I'm trying to do: place the tab bar at the bottom of the iPhone X display where it belongs, and also put the navigation bar at the top of the display.
I've been trying to accomplish what I thought would be a straightforward task of using Safe Areas in the storyboard to position the tab bar near the bottom of the iPhone X's display. I'm missing something fundamental.
I've read a lot of writeup about how to do this, including this one. It includes a screenshot of a tab bar control scene that looks like this:
But I can't create a view inside my Tab Bar Controller to put my tab bar item in, as the article mentions. It's my understanding that I'll use the safe area of the view that should contain the tab bar item. But it won't let me put a view anywhere except outside the Controller view. I've tried using "embed" - but all options are greyed out.
Same goes for a navigation controller to move a navigation bar to the top of the display.
The funny thing is that IB renders it in the right place, but on my device, the tab bar is way above where it should be (and the navigation bar way below).
I have "Opens in" set to "Latest Xcode (9.0) and Builds for iOS 11.1 set in the scene's "Interface Builder Document", and "use Safe Area Layout Guides" is checked. I'm not using any custom classes for my tab bar controller or tab bar. I'm using XCode 9.3 and iOS 11.3.1
What's the simple thing that I'm missing? Thanks in advance.
The article explains how to adapt your app if you're using a custom navigation bar or a custom tab bar.
If you're using the standard navigation bar or tab bar then you have to make sure it's top or bottom (depending on the element) constraints are connected to the superview and not the Safe Area layout guide. UIKit makes sure these elements are correctly rendered with spacing at the top or bottom on an iPhone X device. Check out this screenshot for clarification.

iPhone X - Hidden status bar pushes Navigation Bar upwards

I'm testing iPhone X behavior using the Xcode simulator. For some odd reason, if I'm hiding the Status Bar the Navigation Bar pushed upwards causing the title to completely disappear and cutting the left and right buttons. This is happening only on the iPhone X.
Illustration:
How can I hide the status bar and keep the Navigation Bar at a visible position?
UPDATE:
Sample project for your convince:
https://drive.google.com/file/d/0B5qJARV-Oc9ra1hvZkpXZm9lRUE/view?usp=sharing
One solution is to embed the navigation controller inside a container view controller which is properly constrained to the safe area.
Just create another view controller and drag a "Container View" from the Object Library. This view has top, bottom, leading, and trailing constraints to the safe area, all with constants equal to 0. If you control-drag from the container view to the navigation controller, you'll get an option to set an "embed segue" which will embed the selected view controller as a child view controller.
I set the status bar to be hidden on the new view controller I created, and it works fine.
This feels like something that UINavigationBar should handle automatically, but this workaround seems like it should work pretty well.
Another note: if you change the color of the navigation bar, you'll also need to create another view above the container view, and change its color to match the color of the navigation bar.
I, for a small app, changed from using a Push to a Modal segue and adding in my own navigation bar. I used Push because it looks good, and already had a Modal for another part, which I wanted to animate differently for style reasons.
For smaller apps this may be the quickest and easiest solution, but my next update I need to use the navigation controller. For that I think I'll switch on the status bar, which is no big deal for me and allows it to work.
I think you need to use "safeAreaLayoutGuide" new update in iOS 11
Apple has provided us with the necessary APIs to get around the unsafe regions of this iphone x. We do this by using the new safeAreaLayoutGuide anchors in our code
safeAreaLayoutGuide

Placing a share button over a uiwebview

I have an rss app that I'm working on in xcode and the articles load up in a full screen web view. I need to place a "share" button in the navigation bar but since my uiwebview is full screen it won't show up when I run the app. I even tried cropping the top of the web view lower and placing the button there but still no luck. Here is an example of what I mean:
The share button needs to be on the right side of the navigation bar but i cannot seem to figure out how that make that work.
Thanks in advance
Fist of all, your top navigation bar seems to be missing (judging by your image). Since the nav bar is missing there is no possible way that the share button will be visible. You can do this is the IB or in your code.
For your IB you can move the view controller's 'layer's' so to speak. When you place all the elements down, your VC should look something like this:
On the left hand side we can see what subviews are at the top and which ones are at the bottom.
As we can see here that the UIWebView is at the top of the list, so it'll be at the bottom of the pile. The navigation bars are further down the list so they'll be at the top of the pile. So due to this they'll go over the UIWebView.
The other way to do this is using insertSubview:aboveSubview:. Fist of all you'll add your UIWebView using addSubview: and then add the nav bar using insertSubview:aboveSubview: and finally you'll add your button the someway as you did for the nav bar, but this time you'll be adding the button above the nav bar not the web view.
My best guess is that your forgetting to add another navigation bar to the top of the screen. Hope this helps!!

Xcode 6 Navigation Bar Constraints Issue

I am currently working on a basic app that has many single view view controllers. I am trying to add a navigation bar to one of my view controllers, when using the "Suggested Constraints", I can see nothing. When the only restraint on the Navigation bar is a center horizontal, it shows up but I think it is too long for the screen. When I tried to add a button on the left side of the Navigation bar, it would not show up in my app because the navigation bar does not have the correct width. I know I have the wrong constraint setup, please help.

Animate navigation bar with view during push transition in iOS 7

I'm using the iOS 7 transition API in for some custom transitions. I've got a great transition going, but have problems with the navbar. I want the navigation bar to act as part of the view, so there is a clear line/shadow going the entire vertical length of the screen. (Such as the Reeder app, from this screenshot)
In my view however, the line on the left side of the top view does not extend all the way to the top of the navigation bar.
Just a sample app, so the view stack is generic, and using just a standard UINavigationController.

Resources