自定義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

相關文章
相關標籤/搜索