自定义tabBar在push到下一个界面的时候实现隐藏

        工做中用到了自定义tabBar,在其中隐藏掉了系统的tabBar,用view自定义r实现须要的功能。但接下来出现了问题,在我push到子页面的时候就出现了tabBar没法隐藏的问题,搞了半天终于成功隐藏!在网上查了半天,没有一个方法能够实现,本文步骤稍微多了点,但功能是彻底实现了,废话少说,直入正题。app

        1.  首先自定义一个ZYGNavigationController(名字本身起)继承与UINavigationController,ZYGNavigationController.m中拦截系统的push方法,进行重写:ide

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    viewController.hidesBottomBarWhenPushed = YES; 
    [super pushViewController:viewController animated:animated];
}

-(UIViewController *)popViewControllerAnimated:(BOOL)animated{
    return [super popViewControllerAnimated:animated];
}

       而后给tabbar添加导航的时候就不能用系统的UINavigationController了,而要用咱们自定义的ZYGNavigationController,以下:测试

for (int i=0; i<images.count; i++) {
        Class vcClass = NSClassFromString(viewControllers[i]);
        TabBarParentViewController *controller = [[vcClass alloc] init];
        ZYGNavigationController *nav = [[ZYGNavigationController alloc] initWithRootViewController:controller];//这个地方原本是UINavigationController
        controller.categoryType = categotyArr[i];
        [mArr addObject:nav];
    }
    self.viewControllers = mArr;

         2.  在自定义的TabBarController.m里写以下方法:code

-(void)setHidesBottomBarWhenPushed:(BOOL)hidesBottomBarWhenPushed{
    你本身定义的View.hidden = hidesBottomBarWhenPushed;
}

        3.  在你要隐藏tabbar的界面添加以下两个方法:继承

-(void)viewWillAppear:(BOOL)animated{
    self.tabBarController.hidesBottomBarWhenPushed = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.hidesBottomBarWhenPushed = NO;
}

    作到这一步就完成了,OK,测试一下,perfect!it

    在第三步中,定义一个父类,让其余的界面都继承自该父类,这样只须要在父类里面写一次这样的方法而没必要在每一个界面都重写一次。
io

相关文章
相关标签/搜索