Recreate UITabBar to UIToolbar on select from Photos app - ios

I need to do exactly what the photos app is doing when you press the select button. Basically just hides the UITabBar and presents a UIToolbar. For some reason this seems to be incredibly difficult if you don't want to implement a complete hack. I found a hack if you shrink the height of the UITabBar and change it's alpha to 0 but when you set it's height back to the default the image and text is condensed.

Turns out that I ended up just needing to call [self.tabBarController.tabBar setHidden:YES] to hide the tabBar and instead of using my existing UINavigationController's toolbar I create my own instance of a UIToolbar and add it as a subview of my view controller. Then using autolayout I pinned it to the leading, trailing, and bottom edge of the view. This handles rotation and other issues.

Related

Ios Swift : Adding or Moving NavigationBar to bottom of the view controller

I want to move the navigation controller bar to the bottom of the view controller. How can i get this done ?
I tried :
self.navigationController!.navigationBar.frame = CGRectMake(
0,
UIScreen.mainScreen().bounds.height - 50,
UIScreen.mainScreen().bounds.width,
50)
This is moving to the bottom but hiding all other controller objects and also back button is not woking.
Sujay U N,
You should not try to move the UINavigationBar provided by the embeded UINavigationController to the bottom of the screen. Trying that will obvisoulsy move all the view's below it causing all the controller objects to hide.
Workaround
Approach 1:
Consider using ToolBar :)
Toolbar is designed to be placed at the bottom of the screen. If you are using xib or storyboard you can pick toolbar from components library and place it on your ViewController's bottom and then apply autoresizing masks or constraints properly :)
Now in order to show the back button make use of UIBarButtonItems. Change the style to custom and provide it arrow image or provide default style as done.
Though now you are all set to go :) You will notice UINavigationBar at the top of your view controller. In order to get rid of it,
select your ViewController, select its TopBar property set it to none :)
Approach 2
Use UINavigationBar.
Specific about using Navigation bar and dont want to use toolbar, well you can do the same thing with UINavigationBar as well.
Drag the UINavigationBar from components library place it at the bottom of the screen. Drag the UIBarButtonItem drop it as leftBarButtonItem, change the barButtonItem image to your back image. ( Same process as UIToolBar just use UINavigationBar instead)
Understand this is not same as the navigation bar provided by the embeded NavigationController. So get rid of NavigationBar at the top of your ViewController same as I explained above here as well
Finally,
In both the cases, draw an IBoutlet from barbutton item and handle poping the viewController programmatically.
Happy coding :)

Add a UINavigationBar to a UIView using Autolayout

I have a modal view that I'm presenting over the current view that has a UINavigationBar as a subview. Everything's working great, except that the UINavigationBar doesn't want to behave according to the autolayout constraints. Everything else in the view behaves as desired.
For some reason, the left and right bar button items are cut off on the edges of the view. I inspected the view at runtime to reveal that the total width of the UINavigationBar is the right width, but the bar buttons aren't conforming.
I also checked to make sure I didn't have negative margins or some other anomaly in the constraint definitions.
I have also tried setting the frame of the UINavigationBar manually, but it yielded no improvement.
Problematic View
Constraints
I'd like to keep the UINavigationBar, because it gets styled globally with the rest of my app (as opposed to creating a custom UIView imitation and styling it individually). Does anyone know what handle to jiggle to get the bar button items to conform to the right width?

iOS/Swift: Dynamically Resize a Toolbar

I'm trying to make an app with a toolbar that can be resized. Basically, the toolbar can alternate between being at the bottom of the view and being at the top. When a button is pressed, it switches from one to the other. The problem is that when it is at the top, I want the size of the toolbar to expand to accommodate the status bar, but I don't know how to do this.
I've seen some solutions for changing the toolbar size but they all seem static and not something that can be changed with the tap of a button. Any suggestions on how to do this? Perhaps a different solution altogether?
You can use a normal UIView and customize it so it looks like a UIToolbar, then just set constraints using AutoLayout and animate the height-constraint.

Programmatically add UISegmentedControl in UIToolbar below UINavigationBar

I'm trying to get this to work on iOS 7 and 8+.
In loadView of the viewController, I add a UISegmentedControl, along with flexible spaces, as items to a UIToolBar. I then add the UIToolbar as a subview to the main view, setting the vertical position to be the height of the navigation bar.
First problem. The UISegmentedControl is vertically off center so the top of it, is cut off.
Second problem. Rotating to landscape messes it all up. Specifcally, the UIToolbar seems to move underneath the navigation bar whereas the UISegmentedControl doesn't.
Autoresizing issue? I've tried various settings and can't seem to get it to center vertically within the UIToolbar.
It could be that your UIToolbar constraints are not set properly and also that there is no flexible space around the segmented control. Here's a link to a storyboard file I made that have proper constraints and flexible space, tested to work.
Preview:
Here's the Storyboard file: http://www.filedropper.com/main_4

Add a UIImageView to the back of NavigationBar (NOT background image)

I am trying to add a UIImageView to the back of a navigation bar.
The reason is because I want to create a UITableView whose navigation bar is actually a picture (with back button on the left) but I want the picture to scroll with the tableview and when the picture is fully scrolled out. The navigation bar is shown as per normal.
My solution to this problem:
Add a UIImageView to the top of the UITableView and make the navigation bar transparent. Set a contentOffset for the UITableView which is a subclass of UIScrollView so that when the view is presented, it looks like the picture is filling the navigation status bar.
Problem:
If I scroll up, instead of bouncing back, the transparent status bar is shown (with a color of the background as it is transparent).
Possible way to solve this new problem:
I was thinking of trying to limit the ScrollView size to get around with problem but failed.
So I feel is it possible to add the UIImageView to the "back" of the navigation bar so that it is there without any offset? Since that way, my life will be much easier.
Any suggestions on solving this or another new approach to get the same UI/effect?
Related question.
I would do this by adding either a table header or cell at the top of the table which contains your image.
Create the table view so that it extends all the way to the top of the screen. Extend Under Top Bars option. I have not done this with a UITableViewController but I have done this with a UITableView embedded inside a UIViewController's view with the top constraint set to 0 for the view rather than the top layout guide.
Now when you run this your table will fill the whole screen and the top header or cell will be at the top showing your picture.
When you scroll you can either use the UIScrollViewDelegate to detect the movement or implement tableView:didEndDisplayingCell:forRowAtIndexPath:
I'm not 100% sure when you want the navigation bar to go non clear. If its when the image goes off screen then didEndDisplayingCell should be good. If its when the cell bottom passed under the bottom of the navigation bar then scroll view might be your only option.
This will also bounce as you expect when you pull down and it should snap back to the top.
Hope this helps.

Resources