Reputation: 3
I want to hide my tab bar when I scroll the collection view, code is
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
[self makeTabBarHidden:YES];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self makeTabBarHidden:NO];
}
- (void)makeTabBarHidden:(BOOL)hide
{
if ( [self.tabBarController.view.subviews count] < 2 )
{
return;
}
UIView *contentView;
UIView *bradeView = [self.tabBarController.view.subviews objectAtIndex:2];
if ( [[self.tabBarController.view.subviews objectAtIndex:0]
isKindOfClass:[UITabBar class]] )
{
contentView = [self.tabBarController.view.subviews objectAtIndex:1];
}
else
{
contentView = [self.tabBarController.view.subviews objectAtIndex:0];
}
// [UIView beginAnimations:@"TabbarHide" context:nil];
if ( hide )
{
contentView.frame = self.tabBarController.view.bounds;
}
else
{
contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
self.tabBarController.view.bounds.origin.y,
self.tabBarController.view.bounds.size.width,
self.tabBarController.view.bounds.size.height -
self.tabBarController.tabBar.frame.size.height);
}
self.tabBarController.tabBar.hidden = hide;
bradeView.hidden = hide;
}
but in iOS7 ,when tab bar is hidden , there is a black bar which does not dismiss. How can I hide tabbar in iOS7?
Upvotes: 0
Views: 3712
Reputation: 3380
If you are using segues like me then you should set the view controller property before push. Here is swift example :
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "YOUR_SEGUE_NAME" {
let targetVC = segue.destinationViewController as! YOUR_VIEW_CONTROLLER
targetVC.hidesBottomBarWhenPushed = true
}
Upvotes: 0
Reputation: 3662
BEST ANSWER, call the following method at viewDidLoad and do what @tufyx recommended! Good Luck
- (void)hideTabBar:(UITabBarController *)tabbarcontroller
{
[tabbarcontroller.tabBar setHidden:YES];
UIView *contentView;
if ([[self.tableView.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) {
contentView = [self.tableView.subviews objectAtIndex:1];
} else {
contentView = [self.tableView.subviews objectAtIndex:0];
}
contentView.frame = self.tableView.bounds;
}
Upvotes: 0
Reputation: 163
In your storyboard, select the view controller for which you wish to hide the tab bar, go to attributes inspector, and in the View Controller section > Extend Edges choose the checkbox Under Bottom Bars.
If your bar is opaque select also Under Opaque Bars.
Upvotes: 3
Reputation: 74
use this
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[self setHidesBottomBarWhenPushed:YES];
[super viewWillApper:animated];
}
enter code here
-(void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[self setHidesBottomBarWhenPushed:NO];
[super viewWillDisapper:animated];
}
Upvotes: 1