iOS 7 - hiding tabBar and showing toolBar instead - ios

I have a problem with hiding UITabBar. I have a custom tabBar which I hide using:
self.frame = CGRectOffset(tabBarRect, 0, CGRectGetHeight(tabBarRect));
Instead of tabBar, I want to show toolBar. Everything looks fine, but I noticed the area that was previously occupied by tabBar is not responsive, although I offset the tabBar frame.
So, I just put toolBar as a subview of tabBar:
toolBar.frame = CGRectMake(0, CGRectGetHeight(tbv.frame) - toolBar.intrinsicContentSize.height, CGRectGetWidth(self.view.frame), toolBar.intrinsicContentSize.height);
[tbv addSubview:toolBar];
Unfortunately, my tabBar is bigger than toolBar, so I can't use this solution.
I know that I could add toolBar to appDelegate's keyWindow and on top of tabBar, but I'd like to place it within my viewController.
Is there any way to disable tabBar and use toolBar or any other control with gestures within current viewController that is part of navigation based app with tabBar?
Thank yee

may you can try self.hidesBottomBarWhenPushed =YES;
like this:
self.hidesBottomBarWhenPushed =YES;//hide controller's tabbar
UIViewController *controller =[self.storyboard instantiateViewControllerWithIdentifier:#"MyRequirementParticipateInViewController"];
[self.navigationController pushViewController:controller animated:YES];
self.hidesBottomBarWhenPushed =NO;//when pushed back tabbar would show again.

Related

Unable to click "under" a hidden TabBar

I hide my tab bar like so:
self.tabBarController.tabBar.hidden = YES;
And because now there is a black bar where it once stood I stretch the view which is a UIWebView on top(or is it under?) that empty space. The UIWebView is in a UIViewController. I do that with a constraint which by default is like so:
The code for the constraint:
if(self.tabBarController.tabBar.hidden){
self.webviewBottomConstrain.constant = -self.tabBarController.tabBar.frame.size.height;
}else{
self.webviewBottomConstrain.constant = 0;
}
However if I tap the device on the place where the TabBar was it will not execute. It is as if there is something invisible there with the size of the tab bar. I have also tried hiding it the way this thread sugests. Still the same result.
Update: It seems that when you tap on the invisible tab bar the tap is recognized by the tab bar and not by the view that is visible under the tab bar
self.extendedLayoutIncludesOpaqueBars = YES;
this will solve you problem
You hide your tabBar by setting its hidden property to NO? Try setting it to YES. Unless I am misunderstanding what you are trying to do, it seems like your tab bar is not hidden with that code.
Another thing I would check is to see if User Interaction Enabled is checked for the web view. If it is not, that can seem like there is something invisible blocking you from interacting with your view.
Well I am using quite ugly hack to fix this. I am hiding the tab bar in another way now:
if (shouldShow) {
self.hidesBottomBarWhenPushed = NO;
UIViewController *someView = [[UIViewController alloc] init];
[self.navigationController pushViewController:someView animated:NO];
[self.navigationController popToViewController:self animated:NO];
} else if (shouldHide) {
self.hidesBottomBarWhenPushed = YES;
self.tabBarController.hidesBottomBarWhenPushed = YES;
self.navigationController.hidesBottomBarWhenPushed = YES;
UIViewController *someView = [[UIViewController alloc] init];
[self.navigationController pushViewController:someView animated:NO];
[self.navigationController popToViewController:self animated:NO];
}
I do need that random view because I cannot push the view on itself.
I had the same issue when hiding the tab bar by moving it offscreen to the bottom. My custom UITabBarViewController was intercepting the touch events in the area vacated by the tab bar, so instead of changing the frame of the tab bar to move the tab bar offscreen, I extended the height of my tab bar view controller so that the tab bar still moved offscreen, but the child view above the tab bar now filled that space. This allowed the touches to be received by the child view.
As you may see with view hierarchy instrument, UITabBar is not directly blocking your tap, but your current view controller's view height is not full screen:
So, the tap doesn't response because your finger's y position is higher than view's maxY.
Code like this (inside your UITabBarController) will expand your view's height, according to tabbar visibility, and all tap events will work correctly.
func updateTabBarAppearanceWithDegree(_ degree: CGFloat) {
let screenHeight = UIScreen.main.bounds.size.height
let tabBarHeight = self.tabBar.frame.size.height
self.tabBar.frame.origin.y = screenHeight - tabBarHeight * degree
self.tabBar.alpha = degree
let currentNavigation = self.selectedViewController as? UINavigationController
if let currentTopView = currentNavigation?.viewControllers.last?.view {
currentTopView.frame.size.height = self.tabBar.frame.origin.y
}
}

After hiding TabBar can't touch on the area behind the TabBar

I use a TabBarController on my app, in one of the main views (aViewController) i push another controller (bViewController), and hide the TabBar using self.tabBarController.tabBar.hidden=YES;
bViewController have a button at the same place where the tabBar was, and it doesn't catch the touch event.
I have tried placing the button in different places of bViewController, and the area where the tabBar was supposed to be is the only place where touch event is not detected.
I have tried using bViewController outside the tabBarController and it works fine.
Any help would be appreciated.
EDIT:
When i press a button on aViewController i call
self.tabBarController.tabBar.hidden=YES;
[self performSegueWithIdentifier:#"aViewToBView" sender:self];
aViewToBview is a push segue declared on storyboard
For some reason you cannot touch the views underneath the tab bar.
However, if you hide the tab bar and then add a subview to it, the view can then receive user interaction!
This worked for me:
// Create a button that is at the very bottom of the screen
CGFloat buttonHeight = 45.0f;
UIButton *finishButton = [[UIButton alloc] initWithFrame:CGRectMake(
0,
self.view.frame.size.height - self.tabBarController.tabBar.frame.size.height - buttonHeight,
self.view.frame.size.width,
buttonHeight)];
//...more initialization of the button...
//Here is our solution:
[self.tabBarController.view addSubview:finishButton];

Navigation controller moves all views down by 64px in Storyboard despite it being hidden.

In the View Controller, I set the navigation bar so that
self.navigationController.navigationBar.hidden = YES;
However, I am running into the issue that whichever way my UIViews are laid out in Storyboard, all the UIViews at runtime are moved down 64px. Is there a way that I could set so that both the NavBar is hidden, and that it does not affect how the UIViews are laid out on screen?
Thanks!
Usually , I use this to hide navigationBar.
[self.navigationController setNavigationBarHidden:YES];
While,
self.navigationController.navigationBar.hidden = YES;
Is the property for UIView, this is a method for UINavigationController.

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

iOS 7 | Navigation bar / Toolbar buttons very close to status bar

I have a problem when dragging a navigation bar or toolbar (storyboard) to my view controller.
UINavigationBar:
As you can see in the image above, the right button is almost overlapping the status bar.
With a UIToolbar it happens the same:
This view controllers are intended to be used as a Modal, that's the reason I'm not using a UINavigationController.
In another section I use a UINavigationController and it appears as I expect:
How can I drag a UINavigationBar / UIToolbar to a view controller without overlapping the status bar?
The navigation bars or toolbars have to be at (0, viewController.topLayoutGuide.length) with bar positioning of UIBarPositionTopAttached. You should set the delegate of your navigation bar or your toolbar to your view controller, and return UIBarPositionTopAttached. If positioned correctly, you will have the result in your third image.
More information here:
https://developer.apple.com/documentation/uikit/uibarpositioningdelegate?language=objc
Do these steps
Drag the NavigationBar to your ViewController in Xib, set the ViewController as its delegate.
Note that the NavigationBar should be at (0, 20)
In ViewController, conform to the UINavigationBarDelegate
#interface ETPViewController () <UINavigationBarDelegate>
Implement this method
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
positionForBar tells the NavigationBar if it should extend its background upward the Status Bar
Please see my answer here, I've copied the content below for convenience:
https://stackoverflow.com/a/18912291/1162959
The easiest workaround I've found is to wrap the view controller you want to present inside a navigation controller, and then present that navigation controller.
MyViewController *vc = [MyViewController new];
UINavigationController *nav = [[UINavigationController alloc]
initWithRootViewController:vc];
[self presentViewController:nav animated:YES completion:NULL];
Advantages:
No mucking with frames needed.
Same code works on iOS 6 an iOS 7.
Less ugly than the other workarounds.
Disadvantages:
You'll probably want to leave your XIB empty of navigation bars or toolbars, and programatically add UIBarButtonItems to the navigation bar. Fortunately this is pretty easy.
You can resolve this issue by using Auto Layout, as per this techincal note (Preventing the Status Bar from Covering Your Views).
Here are some excerpts:
Add the Vertical Space Constraint to the top-most view
Control drag from the UIToolbar to the "Top Layout Guide"
In the popover, choose "Vertical Spacing"
Change the "Vertical Space Constraint" Constant to 0 (zero)
If you have other subviews below the UIToolbar, anchor those views to
the toolbar instead of the Top Layout Guide
This will support ios6 and ios7.
You can also manage it by increasing height of navigation bar by providing image of size 620x128 for ios version. And this image is used in :
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)?YES:NO) {
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"newImage.png"] forBarMetrics:UIBarMetricsDefault];
}else{
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"previousImage.png"] forBarMetrics:UIBarMetricsDefault];
}
I gave up and had to set the navbar height constraint to 64 in x xib based VC cause viewController.topLayoutGuide.length is 0 in viewDidLoad despite statusbar being present :-[
which means in a non universal app on ipad you'd have 20 px on the top of the
view wasted (cause status bar is separate from the iphone simulation window)

Resources