码迷,mamicode.com
首页 > 其他好文 > 详细

UITabBar自定义tabbar如何隐藏和显示,超实用

时间:2015-05-13 16:59:08      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:uitabbarcontroller   tarbar   隐藏   

这两天在做新闻客户端,遇到一个问题:如何将作为根视图控制器的自定义UITabBarController在主页转到子页时隐藏

self.tabbarcontroller.tabbar.hidden = YES;

这种方法只适用于系统的tabbar

我打印出了自定义tabbarcontrollerself.tabbarcontroller地址发现不一样

认识到这种误区,我就想办法找到我自定义的tabbarcontroller

我突然想到试图控制器的根控制器就是我自定义的tabbarcontroller(下称Customtabbar

不通过代理找根视图

通过以下方法即可实现对自定义tabbarcontroller的隐藏和显示

UIWindow * window = [UIApplication sharedApplication].keyWindow;

CustomTabBar * ct =(CustomTabBar *) window.rootViewController;

ct.bgView.hidden = YES;


CustomTabbarController.h

#import <UIKit/UIKit.h>
#define kWith [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
@interface CustomTabbarController : UITabBarController

@property (nonatomic,strong) UIView * bgView;

@end


CustomTabbarController.m

#import "CustomTabbarController.h"

@implementation CustomTabbarController
-(instancetype)init{
    self = [super init];
    if (self) {
        
        [self.tabBar removeFromSuperview];// 移除系统自带tabbar
//        self.tabBar.hidden = YES;//隐藏系统自带tabbar  两种方法都能实现让系统自带tabbar消失的效果
        self.bgView = [[UIView alloc]initWithFrame:CGRectMake(0, kHeight-49, kWith, 49)];
        self.bgView.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];
        [self.view addSubview:self.bgView];
    }
    return self;
}
@end





UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用

UITabBar自定义tabbar如何隐藏和显示,超实用

标签:uitabbarcontroller   tarbar   隐藏   

原文地址:http://blog.csdn.net/zx6268476/article/details/45692141

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!