首页 > 其他 > 详细

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

时间:2015-05-13 16:56:14      阅读:261      评论:0      收藏:0      [点我收藏+]

这两天在做新闻客户端,遇到一个问题:如何将作为根视图控制器的自定义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如何隐藏和显示,超实用

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!