【问题标题】:Hiding and Unhiding of tabbar标签栏的隐藏和取消隐藏
【发布时间】:2019-05-13 08:08:51
【问题描述】:

我有一个标签栏控制器。我想在一个视图中隐藏标签栏,并希望在下一个视图中取消隐藏相同的标签栏。隐藏代码适用于第一个视图,但在第二个视图中我取消隐藏标签栏它不起作用..

我的代码:

隐藏:

[[self navigationController] setHidesBottomBarWhenPushed:YES];

对于取消隐藏:

[[self navigationController] setHidesBottomBarWhenPushed:NO];

【问题讨论】:

标签: iphone tabbar


【解决方案1】:

.h

 - (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration;

 - (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration;

.m

- (void) hideTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{

    [UIView transitionWithView:tabbarcontroller.tabBar duration:duration options: UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {

        for(UIView *view in tabbarcontroller.view.subviews)
        {
            if([view isKindOfClass:[UITabBar class]])
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
            } 
            else 
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
            }

        }


    } completion:^(BOOL finished) {


        NSLog(@"tabbar hidden");

    }];


}

- (void) showTabBarOfThisTabbarController:(UITabBarController *) tabbarcontroller withAnimationDuration:(int)duration{


    [UIView transitionWithView:tabbarcontroller.tabBar duration:duration options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction animations:^(void) {



        for(UIView *view in tabbarcontroller.view.subviews)
        {
            NSLog(@"%@", view);

            if([view isKindOfClass:[UITabBar class]])
            {
                [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];

            } 
            else 
            {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
            }


        }


    } completion:^(BOOL finished) {


        NSLog(@"tabbar shown");

    }];


    //u can call like this

    //[self hideTabBarOfThisTabbarController:self.tabBarCon withAnimationDuration:3];

    //if u want immediately hide/show the tabbar then duration should be 0.0

【讨论】:

  • 停止在这么多答案的情况下转储相同的代码块。
  • @Tim Post 我花了大约 3 个小时来完成这项工作。所以我分享了所有这些内容以及他们可以获得有关我的答案的通知。好的,我不会再重复了。我忘记了只是通过了链接。对不起。我不会再犯这个错误了
  • 你可以在cmets中传递链接,这样就很好了。还请在这个答案中添加一些上下文,现在它只是一个代码转储,可能会让人们忽视它的用处。
  • @tim ok buddy.indeed 我给了他们评论。从我的下一篇文章中我会尽我所能。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-15
  • 1970-01-01
  • 1970-01-01
  • 2018-02-22
相关资源
最近更新 更多