How to hide UITabBar under iOS6 and iOS7

Source: Internet
Author: User

How to hide UITabBar under iOS6 and iOS7

If you don't stick to it, you won't make progress!

These two days are compatible with iOS6, and the original region does not respond to the Click Event After UITabBar is hidden. This will happen if you don't care about it )!

For iOS7, it is easy to hide UITabBar:

Self. tabBarController. tabBar. hidden = YES;

Then, add the height of self. view to the height of a tabBar (the default height is 49). This is a breeze! IOS7 and below won't work!

Here is a piece of code that can be used by iOS6 and later systems, and I am sticking it directly.

 

  1. -(Void) makeTabBarHidden :( BOOL) hide {// Custom code to hide TabBar
  2. If ([tabBarController. view. subviews count] <2) {return;
  3. }
  4. UIView * contentView; if ([[tabBarController. view. subviews objectAtIndex: 0] isKindOfClass: [UITabBar class]) {
  5. ContentView = [tabBarController. view. subviews objectAtIndex: 1];} else {
  6. ContentView = [tabBarController. view. subviews objectAtIndex: 0];}
  7. If (hide ){
  8. ContentView. frame = tabBarController. view. bounds;} else {
  9. ContentView. frame = CGRectMake (tabBarController. view. bounds. origin. x, tabBarController. view. bounds. origin. y,
  10. TabBarController. view. bounds. size. width, tabBarController. view. bounds. size. height-
  11. TabBarController. tabBar. frame. size. height );}
  12. TabBarController. tabBar. hidden = hide;
  13. }

     

    Tested and reliable, there is no need to worry about the failure to respond to click events in the region after UITabBar is hidden under iOS6!

    When I first saw this code, I turned a blind eye and didn't try it. Afterwards, it also annoyed me (I think I should deserve it )!

    My colleague tried it and it worked! Regret it. Take a look .......

    Let me analyze this Code:

    On iOS6, UITabBar is located on the self. view of a viewController.

    Self. tabBarController. tabBar. hidden = YES;

    Then you do.

    [Self. tabBarController setTabBarItem: nil];

    Even you do.

    [Self. tabBarController. tabBar removeFromSuperView];

    Finally, you will find that the area occupied by tabBar still cannot respond to the click event. In iOS6, it will occupy the pitfalls, so you can't take it...

    So use the above Code!

    I'm just angry with the fact that tabBar on iOS6 is not pulling!

    Practical

    In other words, I am writing a subclass that inherits from UITabBarController. In the viewDidLoad method, I found that self. view has two subviews at the beginning. One is tabBar, which occupies self. the height at the bottom of the view is 49, and the other is contentView (I would like to say this, but the specific name is estimated to ask xcode's father ). in systems below iOS 7, when you remove the tabBar, contentView will not automatically extend its height, so you have to manually add the height of the tabBar. For iOS 7 and later systems, Apple's developers should help us with this activity, so we can just hide it.

    I understand it myself. please correct me!


     

     

     

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.