您的位置:首页 > 移动开发 > IOS开发

iOS开发-隐藏Tabbar的一些方法

2013-11-06 15:33 405 查看
由于手机界面比较小,有时候由于业务的需要,需要隐藏那个导航用的tabbar,方法有下面几个方法

 

方法一 

    YourAppDelegate *app = (YourAppDelegate *)[UIApplication sharedApplication].delegate;

   

    NSArray *views = [app.tabBarController.view subviews];

    for(id v in views){

        if([v isKindOfClass:[UITabBar class]]){

            [(UITabBar *)v setHidden:YES];

        }

至于是隐藏还是显示根据自己的业务需求,在ViewController的不同的生命周期里执行,

推荐在下面2个方法里隐藏和显示 

- (void)viewWillAppear: (BOOL)animated 

- (void)viewWillDisappear: (BOOL)animated  

 

方法二

   [viewController setHidesBottomBarWhenPushed:YES];

这个方法在viewcontroller push navigation之前执行,也还比较方便

 

方法三

     - (void) hideTabBar:(BOOL) hidden

    {  

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:0];

    

    for(UIView *view in self.tabBarController.view.subviews)

    {

        if([view isKindOfClass:[UITabBar class]])

        {

            if (hidden) {

                [view setFrame:CGRectMake(view.frame.origin.x, 320, view.frame.size.width, view.frame.size.height)];

            } else {

                [view setFrame:CGRectMake(view.frame.origin.x, 320-49, view.frame.size.width, view.frame.size.height)];

            }

        } 

        else 

        {

            if (hidden) {

                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 320)];

            } else {

                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 320-49)];

            }

        }

    }

    [UIView commitAnimations];

}

 

 这个方法,没有试过,如果把frame的位置调整好,应该是可以解决的但是在解决横屏和竖屏的时候,可能要花点功夫。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息