直接继承一个UITabBar会比隐藏tabbarcontroller麻烦吗

隐藏UITabBarController&并去掉隐藏后的白边
自定义的 ipad版:
setAnimationDuration:0.0];
[UIView beginAnimations:nil context:NULL];
& & for(UIView *view in self.view.subviews)
& & & & if([view isKindOfClass:[UITabBar class]])
& & & & & & NSLog(@"%@", view);
& & & & & & view.hidden = YES;
& & & & } else {
& & & & & & [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 1024)];
& & [UIView commitAnimations];
BOOL hiddenTabBar;
UITabBarController *tabBarController;
- (void) hidetabbar {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabBarController.view.subviews)
NSLog(@"%@", view);
if([view isKindOfClass:[UITabBar class]])
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
[UIView commitAnimations];
此方法限于&UITabBarController + UINavigationController :
在pushViewController之前调用
[self setHidesBottomBarWhenPushed:YES];
同时在viewWillDisappear调用:
- (void)viewWillDisappear:(BOOL)animated
setHidesBottomBarWhenPushed:NO];&
&&& [super
viewDidDisappear:animated];&
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。自定义UITabBarController的TabBar视图_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
自定义UITabBarController的TabBar视图
无​限​互​联​i​O​S​开​发​自​定​义​视​图​,​设​置​代​码​。
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢UITabBar自定义tabbar如何隐藏和显示,超实用 - CSDN博客
这两天在做新闻客户端,遇到一个问题:如何将作为根视图控制器的自定义UITabBarController在主页转到子页时隐藏
self.tabbarcontroller.tabbar.hidden =
这种方法只适用于系统的tabbar
我打印出了自定义tabbarcontroller和self.tabbarcontroller地址发现不一样
认识到这种误区,我就想办法找到我自定义的tabbarcontroller
我突然想到试图控制器的根控制器就是我自定义的tabbarcontroller(下称Customtabbar)
不通过代理找根视图
通过以下方法即可实现对自定义tabbarcontroller的隐藏和显示
UIWindow * window = [UIApplication sharedApplication].keyW
CustomTabBar * ct =(CustomTabBar *) window.rootViewC
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 * bgV
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];
UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用UITabBar自定义tabbar如何隐藏和显示,超实用【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式_-IT行业第一站
【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
标题:【iOS开发-31】UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式
一、对UITabBar背景和icon图标的一些设置
(1)因为直接给UITabBar设置的背景颜色显示的不纯,半透明的感觉,所以,有时候我们可以直接利用纯色的图片作为背景达到想要的效果;
(2)给icon图片改变颜色也是重要的实用方法之一,默认的时蓝色。
在AppDelegate.m文件中:(1个导航控制器和5个视图控制器)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//创建5个视图控制器和1个导航控制器
ViewController1 *vc1=[[ViewController1 alloc]init];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:vc1];
ViewController2 *vc2=[[ViewController2 alloc]init];
ViewController3 *vc3=[[ViewController3 alloc]init];
ViewController4 *vc4=[[ViewController4 alloc]init];
ViewController5 *vc5=[[ViewController5 alloc]init];
ViewController *vc6=[[ViewController alloc]init];
nav1.title=@&界面1&;
vc2.title=@&界面2&;
vc3.title=@&界面3&;
vc4.title=@&界面4&;
vc5.title=@&界面5&;
vc6.title=@&界面6&;
//6个系统icon图标
[nav1.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:1];
[vc2.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemSearch tag:2];
[vc3.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemContacts tag:3];
[vc4.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:4];
[vc5.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemMostRecent tag:5];
[vc6.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:6];
//创建一个视图控制器数组,并把它赋值给标签栏控制器的viewControllers值
NSArray *arr1=[[NSArray alloc]initWithObjects:nav1,vc2,vc3,vc4,vc5,vc6, nil];
UITabBarController *tbCon1=[[UITabBarController alloc]init];
tbCon1.viewControllers=arr1;
//标签栏控制器有个tabBar属性,这个属性有两个items和selectedItem属性是不能用的,因为这两个属性是归标签栏控制器直接管理,其他人不能对其赋值
//运行以下两行代码,程序会崩溃
//tbCon1.tabBar.items=[[NSArray alloc]initWithObjects:vc1.tabBarItem, nil];
//tbCon1.tabBar.selectedItem=vc1.tabBarI
//通过backgroundColor可以设置标签栏颜色,但是是一层淡淡的红色
tbCon1.tabBar.backgroundColor=[UIColor redColor];
//可以通过设置背景图片的方式给标签栏设置背景颜色,比如红色的背景图片,要求图片大小要正好
//用以下方式获得标签栏宽高后,创建一个背景图片,再引入进来
NSLog(@&%i,%i&,(int)tbCon1.tabBar.frame.size.height,(int)tbCon1.tabBar.frame.size.width);
tbCon1.tabBar.backgroundImage=[UIImage imageNamed:@&tabBarbg.png&];
//通过tintColor可以给icon图标设置颜色
tbCon1.tabBar.tintColor=[UIColor redColor];
//设置被选中标签的背景图片,宽度是375/5=77
tbCon1.tabBar.selectionIndicatorImage=[UIImage imageNamed:@&selectionDic.png&];
//把这个标签栏控制器当做window的根视图控制器来显示
self.window.rootViewController=tbCon1;
// Override point for customization after application launch.
return YES; }
二、隐藏UITabBar的第一种方式
这一种方式需要用导航控制器视图来做实验,因为我们需要用hidesBottomBarWhenPushed属性,这个属性的意思是,当这个视图被压到栈中时(导航控制器的栈),隐藏底部的bar,包括UITabBar。
所以我们以上面的nav1做实验,nav1的根视图控制器是vc1,我们在vc1中增加一个按钮,一点击就到ViewController7.m中(实例是vc7),并隐藏UITabBar。
#import &ViewController1.h& #import &ViewController7.h&
@interface ViewController1 ()
@implementation ViewController1
- (void)viewDidLoad {
UIButton *btn1=[UIButton buttonWithType:UIButtonTypeRoundedRect];
btn1.frame=CGRectMake(38, 80, 300, 30);
btn1.backgroundColor=[UIColor whiteColor];
[btn1 setTitle:@&PUSH& forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(jumpTo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn1];
[super viewDidLoad];
// Do any additional setup after loading the view. }
-(void)jumpTo{
ViewController7 *vc7=[[ViewController7 alloc]init];
[self.navigationController pushViewController:vc7 animated:NO]; }
在ViewController7.m中:
#import &ViewController7.h&
@interface ViewController7 ()
@implementation ViewController7 //增加一个initWithNibName方法,标配是return self。此外还需要在初始化时就设置它的hidesBottomBarWhenPushed属性为YES才能生效 //即,在视图控制器的实例被加载到栈之前,就需要设置这个属性,否则无效 -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self.hidesBottomBarWhenPushed=YES; }
三、隐藏UITabBar的第二种方式
就是把UITabBar的位置移动,即调整frame.origin.y的值。消失就是把它移出屏幕,出现就是把它再放回原地。(但,还原时又卡顿现象,体验很差,不建议)
所以,在ViewController7.m中:
//增加一个试图即将出现时的方法,并在此设置把tabBar下移,移除整个屏幕,相当于消失了 -(void)viewDidAppear:(BOOL)animated{
NSArray *arr1=self.tabBarController.view.
UIView *view1=[arr1 objectAtIndex:0];
UITabBar *tabBarView1=[arr1 objectAtIndex:1];
//第一个视图就是全屏,不需要把高度撑满,所以可以不做任何设置
//view1.frame=CGRectMake(0, 0, 375, 667);
tabBarView1.frame=CGRectMake(0, 667, 375, 49); }
在ViewController1.m中:
//增加一个viewDidAppear,把下移的tabBar再上移,相当于还原到原地 -(void)viewDidAppear:(BOOL)animated{
NSArray *arr2=self.tabBarController.view.
UITabBar *tabBarView2=[arr2 objectAtIndex:1];
tabBarView2.frame=CGRectMake(0, 618, 375, 49); }
其实还有一种隐藏方式,但是极具杀伤力,一隐全隐了,就是从根源上设置这个标签控制器不显示UITabBar。就是下面的第二行代码:
UITabBarController *tbCon1=[[UITabBarController alloc]init];
tbCon1.tabBar.hidden=YES;
延伸阅读:
热门搜索:}

我要回帖

更多关于 uitabbar隐藏 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信