Auto Layout and "Hide bottom bar when pushed" - ios

My app's (simplified) structure is this:
UITabBarController with one UINavigationController holding a UITableViewController as root view controller.
when tapping one of the table view controller cells, I push a regular UIViewController (lets call it VC) end hiding the bottom tab bar. (using the "Hide bottom bar when pushed" flag)
In storyboard I added a regular UIView subclass to VC that look like a bottom bar, and I use Auto Layout to pin it to the bottom of the VC view.
The problem
when I push VC it takes a second for this view to pin to the bottom, it looks like auto layout pin it to the bottom as if the tab bar is not hidden and after a sec it recognise that the tab bar is hidden and moves it to the real bottom of the view.
I know its not the best explanation, so I added a very simple project to demonstrate the issue.

The problem is with this specific constraint which is between the view and the top of the bottom layout guide.
Select the constraint and edit its "Second Item" property
Here you need to choose bottom
Once you have that, the pink view is not influenced by layout guide anymore. The layout guide seem to acknowledge that the tab bar is hidden only after the root view of the pushed view controller is in the bounds of main screen and this happens only when the animation is finished.
And that is the reason the view hierarchy needs to be laid out again which causes the unwanted animation.

The accepted answer did not work for me (the option was not available). However I have found another solution. (based on Hide Bottom Bar When Pushed through Autolayout)
Select booth the view and the object to align (in my case btnShare) and add a new alignment constraint (Bottom Edges).

Hi In storyboard select Tab bar (Is Tab Bar Controller Scene > Tab Bar Controller > Tab Bar ), in the attribute inspector, uncheck Translucent box. This action fix your problem. (But there are many things, "Hide bottom bar when pushed" is to toolbar).

Select your "Navigation Controller" and in "Attribute Inspector" remove the checkmark from "Under Bottom Bars".

IF you can't select bottomlayoutguide bottom in your Xcode 7+
just do the following:
open your storyboard in source code editor
search your controller's identifier
find <layoutGuides>, type <bottom>, copy it id
search by id
change attribute from top to bottom
enjoy.

In the storyboard, Go to the View Controller that you want to hide the tab bar, click on Attribute Inspector and select Hide bottom bar when pushed. Check image bellow.

If you want the tab bar to be hidden, you can add this code to your controller,
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tabBarController.tabBar.hidden = YES;
}
You will also have to put that code (but passing NO) into the controller where you want the tab bar to be visible. You should also deselect the "Hide bottom bar when pushed" box in IB.
After Edit:
You'll get a better animation if, in the first controller, you animate the alpha value of the non-hidden tab bar from 0 to 1 over a short time. This looks good if you go back with the back button. If you want to use the swipe back, you would have to do something more complicated involving the interactivePopGestureRecognizer.
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tabBarController.tabBar.hidden = NO;
self.tabBarController.tabBar.alpha = 0.0;
[UIView animateWithDuration:.4 animations:^{
self.tabBarController.tabBar.alpha = 1.0;
}];
}

-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tabBarController.tabBar.hidden = NO;
self.tabBarController.tabBar.alpha = 0.0;
[UIView animateWithDuration:.3 animations:^{
self.tabBarController.tabBar.alpha = 5.0;
}];
}

set UINavigationBar Translucent with NO.
like this: self.navigationController.navigationBar.translucent = NO;

Try pinning bottom of your view to bottom of superview and not bottom-layout

Related

hideBottomBarOnPush not working on child views

Pushing using segues with parameter on performSegues will hide the bottom bar when hidesBottomBarOnPush is set to true, the problem is on the child view of the view that has been hidden you cannot show/unhide the bottom bar. Already tried hidesBottomBarOnPush = false. Is there any way to unhide the bottom bar when the parent view's bottom bar is hidden.
Edit:
If I use the tabBar.hidden a small white rect will be shown at the bottom of the view. And also another problem with that is, when I change to another tab then go back to the tab I'm working on, the child view is retained but tabBar becomes hidden.
Legend:
3rd view controller - is the parent view that push segues.
4th view controller - is the child view.
Hoping someone can help me with this problem.
if you want to hide the bottom bar in one particular view controller,and show in others, try this, i think this works better than hidesBottomBarOnPush
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.tabBarViewController.tabBar setHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear];
[self.tabBarViewController.tabBar setHidden:NO];
}

UIView overlapping Navigation Bar

In a viewController I programmatically create a UIView that has the same height of the screen. The problem is that navigation bar is still visible and clickable, but I want it to go under the new view. How can I do that?
EDIT: this is a screenshot of what I have now
Not sure if this is what you actually want, since hiding it is a quite acceptable thing to do. However you can hide the rightButtonItem and disable the left one:
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.backBarButtonItem.enabled = NO;
And to get back your right bar button, if you need it again somewhere:
self.navigationItem.rightBarButtonItem = self.*whatever*ButtonItem;
See if that works. I'm away from my Mac at the moment, so can't check it myself.
Right now you have taken navigation controller as a root view
controller (Maybe),In this case navigation controller overlaps the
UIVewController's view that's why it comes on the view so you need to
hide the Navigation controller.
What about making it hidden?
self.navigationController.navigationBarHidden = YES;

alternating between toolbar / tab bar

my app is structured as follow: UITabBarController > UINavigationController > ViewControllerOne > ViewControllerTwo.
the UINavigationBar has at the bottom the tab bar, now when the user navigates into the second view controller, i want to be able to hide the tab bar and replace is with a tool bar. i tried this code:
[self.navigationController.tabBarController.tabBar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];
when i run the app the tab bar is hidden but the toolbar doesn't appear. plus, since the last VC is a table view controller, when i scroll through the cells there is a white gap between the table and the bottom of the view. how can i fix that?
That won't work because when you hide the tab bar like that the subviews won't be adjusted properly (that's why you get the white space). You'll have to use
self.hidesBottomBarWhenPushed = YES;
In your init method or awakeFromNib... and then
[self.navigationController setToolbarHidden:NO animated:YES];
In the viewDidLoad for example.
That way the tab bar controller's view is going to layout correctly it's subviews when you hide the tab bar. Just remember to call self.hidesBottomBarWhenPushed = NO; in your first view controller otherwise the tab bar is still going to be hidden when the second view controller is popped from the navigation stack.
Try to assigning toolbar with appropriate frame and adding it to self.tabBarController.view

iOS7: avoid UItableView or other views to fall under UITabBar [duplicate]

In my storyboard, I have a View controller (embedded in a navigation controller).
Inside the view controller I have a tab bar controller, and inside a tab a table view controller. My problem is that the last row of the table view goes "under" the tab bar of the tab bar controller. This didn't happen if i build my app for iOS 6.
How can I solve this? Thank you!
Try setting your tabbar translucent property.
self.navigationController.navigationBar.translucent= NO; // Set transparency to no and
self.tabBar.translucent= NO; //Set this property so that the tab bar will not be transparent
The accepted and upvoted answers don't work for my setup:
UITabBarController -> UINavigationController -> UIViewController -> UITableView
My app's root view controller is a UITabBarController. Every tab is a UINavigationController, and in one tab, the navigation controller's root is a UIViewController with a table view as the main view.
So here's what worked for me: When alloc-initing the UITableView, I compute for the height and set it in the table view's frame. The general formula is screen height - (status bar height + nav bar height + tab bar height).
This, as said, will work perfectly. I've just tested it.
self.tabBar.translucent = NO;
I think it has to do with automaticallyAdjustsScrollViewInsets not being applied (or applied correctly) due to the nested structure of your view controller hierarchy.
Try and copy your table into a new UIViewController and make sure the checkmark in the UIViewController's identity inspector called "Adjust Scroll View Insets" is turned on.
I had the same problem, and the up-voted answers did not solve it. See my answer to a similar question, Tab Bar covers TableView cells in iOS7.
I solved the issue by manually setting the table view's frame in the table view controller's viewWillAppear: method (as suggested by Matt Quiros) to the height of the screen - (status bar height + nav bar height + tab bar height).
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Adjust height of tableview (does not resize correctly in iOS 7)
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.size.height = [self heightForTableView];
self.tableView.frame = tableViewFrame;
}
- (CGFloat)heightForTableView
{
return CGRectGetHeight([[UIScreen mainScreen] bounds]) -
(CGRectGetHeight([[UIApplication sharedApplication] statusBarFrame]) +
CGRectGetHeight(self.navigationController.navigationBar.frame) +
CGRectGetHeight(self.tabBarController.tabBar.frame));
}
If anyone finds a better solution to this problem, please share!

iOS 7 status bar transparent

In storyboard, in a view controller I tried add a navigation bar under the status bar, running it, it is transparent and shows a label that's supposed to be blurred, like by navigation bar.
But when placing the same view controller embedded in a navigation view controller, the underneath background image could be blurred, which is my intention.
What are these two way different results? What need to do for the firs method to make status bar blur?
Thanks!
In iOS 7 the status bar is transparent by default. The blurring you're seeing when there's also a navigation bar is actually created by the navigation bar. So to create the effect you're looking for without a navigation bar, you need to position a view that produces a blurring effect beneath the status bar.
For reference, add your view with a frame provided by:
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
I know this is old, just for reference, I solved this by setting self.navigationController.navigationBar.clipToBounds = NO
I haven't tested this completely, but go to your plist file and check the following settings:
"View controller-based status bar appearance": If this is set to "Yes", then it should display a status bar that is unique to each View Controller, which might be what you need.
"Status bar style": You may set this to three different styles: Opaque black, Gray, and Transparent black.
Let me know if this worked for you.
UINavigationController will alter the height of its UINavigationBar to either 44 points or 64 points, depending on a rather strange and undocumented set of constraints. If the UINavigationController detects that the top of its view’s frame is visually contiguous with its UIWindow’s top, then it draws its navigation bar with a height of 64 points. If its view’s top is not contiguous with the UIWindow’s top (even if off by only one point), then it draws its navigation bar in the “traditional” way with a height of 44 points. This logic is performed by UINavigationController even if it is several children down inside the view controller hierarchy of your application. There is no way to prevent this behavior.
It looks like you are positioning your view hierarchy in the first example starting at the point (0,20). Also, is that a UIToolbar or a UINavigationBar? If it's the latter, why are you using it by itself and not using it inside of UINavigationController?
If you do not use UINavigationController and are instead using custom view controller containers, you'll need to position your views accordingly.
See this answer for a thorough explanation.
I have similar UI design and based on Matt Hall answer and some article I've googled, I come up with something like this:
- (void)viewDidLoad {
[super viewDidLoad];
if (NSFoundationVersionNumber>NSFoundationVersionNumber_iOS_6_1) {
CGRect statusBarFrame = [self.view convertRect: [UIApplication sharedApplication].statusBarFrame fromView: nil];
UIToolbar *statusBarBackground = [[UIToolbar alloc] initWithFrame: statusBarFrame];
statusBarBackground.barStyle = self.navBar.barStyle;
statusBarBackground.translucent = self.navBar.translucent;
statusBarBackground.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[self.view addSubview: statusBarBackground];
}
}
Where self.navBar points to navigation bar added in storyboard. This is needed only in case when it runs on iOS7 that is why I've added this condition (my app has to support iOS5).
This works like a charm.
alternative approach (enforce status bar size) is also good:
- (void)viewDidLoad {
[super viewDidLoad];
if (NSFoundationVersionNumber>NSFoundationVersionNumber_iOS_6_1) {
CGRect statusBarFrame = [self.view convertRect: [UIApplication sharedApplication].statusBarFrame fromView: nil];
self.navBar.frame = CGRectUnion(statusBarFrame, self.navBar.frame);
}
}
I've found another solution I think this is best since it involve only storyboard and no code is required.
Switch storyboard view to 6.1 mode (view as: iOS 6.1 and Earlier)
Select problematic UINavigationBar
in size section add 20 delta height in "iOS6/7 Deltas"
Switch back view to 7.0 mode (view as: iOS 7.0 and Later), and be happy with result.
when you embed view controller with navigation view controller that time you will see navigation bar to all the view controller you are pushing to from same view controller. In your first case you are adding the navigation bar object, insted of that you can select view controller from storyboard , go to attributes inspector tab & from their select Top bar as translucent navigation bar.

Resources