How to hide Uitabbar under IOS6 and IOS7

Source: Internet
Author: User
Tags vars

Without a somersault, you will not progress!

These two days to match iOS6, in Uitabbar hidden after the original area does not respond to click on the issue of the incident, abnormal fire (not intentions, will be like this)!

For IOS7, hiding Uitabbar is easy:

Self.tabBarController.tabBar.hidden = YES;

Then the height of the Self.view plus a tabbar height (the default height of 49) is OK, it is effortless! IOS7 below!

Here is a code, IOS6 and above system can be used, I just glued it.

  1. -(void) Maketabbarhidden: ( BOOL ) Hide {
  2. //Custom code to hide TabBar   
  3. if   ([Tabbarcontroller. Viewsubviews count] < 2 ) {
  4. return   ;
  5. }
  6. UIView     *contentview;
  7. if ([[Tabbarcontroller. View. subviews objectatindex:0 ] iskindofclass: [Uitabbar class]]) {
  8. Contentview = [Tabbarcontroller. View. subviews objectatindex:1];
  9. } Else {
  10. Contentview = [Tabbarcontroller. View. subviews objectatindex:0   ];
  11. }
  12. if (hide) {
  13. Contentview. Frame = Tabbarcontroller. View. Bounds;
  14. } Else {
  15.            contentview.frame  = cgrectmake (tabbarcontroller .view .bounds .origin .x ,                   
  16.                                            tabbarcontroller .view .bounds .origin .y ,    
  17.                                            tabbarcontroller.view .bounds .size .width ,    
  18.                                            tabbarcontroller .view .bounds .size .height  -   
  19. Tabbarcontroller. TabBar.frame. Size. Height);
  20. }
  21. Tabbarcontroller. TabBar. Hidden = hide;
  22. }

Tested, reliable, and no longer have to worry about iOS6 under the Uitabbar hidden after the area is still dead or alive can not respond to the issue of click events!

The first time I saw this code, I was blind, I did not try, and afterwards, it also made me extremely annoyed (I think I deserve it)!

My colleague tried it and it worked! Hadn't. Take a look more ....

Let me analyze This code:

On the IOS6, Uitabbar is located on the top of a viewcontroller self.view, if you use

Self.tabBarController.tabBar.hidden = YES;

And then you do.

[Self.tabbarcontroller Settabbaritem:nil];

Even if you do it again

[Self.tabBarController.tabBar Removefromsuperview];

Finally you will find that the area of Tabbar is still unable to respond to the Click event, on the iOS6 it also occupies the manger not pull, you really take it did not recruit ...

So use the code above!

Do not say what, I just on this iOS6 Tabbar occupy manger not pull behavior very indignation!

Say something practical.

What I'm writing here is a subclass that inherits from Uitabbarcontroller, and in the Viewdidload method I find that Self.view at first there are two Subview, one is Tabbar, this cargo occupies the height of 49 below Self.view, the other is Contentview (I would like to call, The specific name is estimated to ask Xcode its father. IOS7 the following system when you take Tabbar off, Contentview will not automatically extend their height, so you have to manually help it to the height of the Tabbar to add. and iOS7 and above the system, the Apple developer should help us to put this work to dry, so we hide on the line.

My own understanding, welcome correction!


Code from http://blog.csdn.net/yongyinmg/article/details/40050089




How to hide Uitabbar under IOS6 and IOS7

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.