UITabarController实践

来源:互联网 发布:淘宝网羽绒服半成品 编辑:程序博客网 时间:2024/06/05 04:30

一、自定义UITabbarController使用

       UITabarController继承于UIViewcontroller,维护着一组UIViewcontroller或者subclass of  UIViewcontroller的实例,控制他们显示、隐藏和切换。UITabarController作为IOS开发中比较常用的分页容器,多种情况下系统原生的可以满足使用。但是在适配不同系统版本UI或者需要深度定制的情况下,还是自定义比较方便。

      自定义主要是隐藏原生的tabbar,然后自己创建实现tabbar的功能。便于更好的控制和UI定制。

       1、首先创建subclass of  UITabarController:MyTabbarController 。

       2、初始化的时候,隐藏掉native  tabbar。self.tabbar.hidden = YES.

       3、创建custom  tabbar需要的所有subview,backView和各个tab操作button等。add在MyTabbarController的view之上,位置刚好是tabbar的位置。

      使用场景:MyTabbarController中放置了三个UINavigationController。在某个nav  rootviewcontroller vc1 push到vc2的时候

,需要隐藏cutom tabbar。隐藏之后,在tabbar的地方,有white space存在,其frame和tabbar的相同。于是使用

vc2.hidesBottomBarWhenPushed = yes来达到,在vc2被push的时候,隐藏掉bottombar。但是返回vc1的时候,发现native tabbar出现了。而原来native tabbar是隐藏掉的。所以推测调用hidesBottomBarWhenPushed会使nativetabbar显示出来。

      
0 0
原创粉丝点击