[Original] iOS learning UITabBar hiding, iosuitabbar

Source: Internet
Author: User

[Original] iOS learning UITabBar hiding, iosuitabbar

When the page uses the UITabBarController + UINavigationController framework, when you jump to the details page, if the UITabBar still exists, it will cause logical confusion and the user experience will also decrease, therefore, we have a need to hide UITabBar on the details page. Of course, in other cases, we may also need to hide UITabBar, here, we will introduce three methods to hide UITabBar. You can select one based on your detailed requirements.

1. First:

Hide the UITabBar of the current page

// Display tabBarself. tabBarController. tabBar. hidden = NO; // hide tabBarself. tabBarController. tabBar. hidden = YES;

2. Type 2:

Hide the UItabBar of the pushed page

// Hide tabBarUIViewController * vc2 = [UIViewController new] During push jump; vc2.hidesBottomBarWhenPushed = YES; [vc1 pushViewController: vc2 animated: YES];

This method is used when pushing pages. It has some limitations. According to its name, it can be found that the method takes effect only when pushing jumps, that is to say, it can be used in combination with UITabBarController and UINavigationController.

This is exactly the situation that xiaobian mentioned at the beginning. I think it is also a common situation!

3. Third:

Modify the frame of the subview of TabBar without using the existing methods and custom methods provided by the system.

Principle:

There are two subviews of UITabBarController. One is UITabBar, which is the bottom Bar. The other is UITranstionview, which is the view above the Bar. There are other subviews under these two views, so you don't have to worry about them. Move the y of UITabBar down to 49 units, and lengthen the hight of UITranstionview to 49 units.

Code 1:

- (void)hidesTabBar:(BOOL)hidden{          [UIView beginAnimations:nil context:NULL];     [UIView setAnimationDuration:0];          for (UIView *view in self.tabBarController.view.subviews) {         if ([view isKindOfClass:[UITabBar class]]) {             if (hidden) {                 [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];                             }else{                 [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];                              }         }else{             if([view isKindOfClass:NSClassFromString(@"UITransitionView")]){                 if (hidden) {                     [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];                                      }else{                     [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];                                     }             }         }     }     [UIView commitAnimations];      }

Code 2:

-(void)makeTabBarHidden:(BOOL)hide { // Custom code to hide TabBar    if ( [self.tabBarController.view.subviews count] < 2 )    {        return;    }    UIView *contentView; 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];    }    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;}

 

The above are three methods summarized by the editor. They are also summarized from the blogs of the great gods. If you have any new methods, please join us!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.