iOS-如何使用动画隐藏/显示UITabBarController的标签栏? [英] iOS- How to Hide/Show UITabBarController's tab bar with animation?

查看:245
本文介绍了iOS-如何使用动画隐藏/显示UITabBarController的标签栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对iOS的UITabBarController的标签栏有疑问.

I have a question about iOS's UITabBarController's tab bar.

我正在使用UITabBarController来显示一些视图,但是我希望这些视图以尽可能大的屏幕显示.是否可以隐藏选项卡栏,使其通常不显示,直到用户触摸屏幕,然后选项卡栏(带有动画)才会显示在底部.然后,几秒钟后,如果什么也不做,则选项卡栏将再次消失,从而使视图再次回到全屏显示状态.

I'm using a UITabBarController to display a few views, but as I want the views to be displayed with as large a screen as possible. Is it possible to hide the tab bar so that it normally doesn't show, until the user touches the screen, then the tab bar will (with animation) show up at the bottom. Then, after a few seconds, if nothing is done, then the tab bar will again go away, so that the view going back to be full screen again?

推荐答案

这是显示方式

- (void)showTabBar:(UITabBarController *)tabbarcontroller
{
    tabbarcontroller.tabBar.hidden = NO;
    [UIView animateWithDuration:kAnimationInterval animations:^{
        for (UIView *view in tabbarcontroller.view.subviews) {
            if ([view isKindOfClass:[UITabBar class]]) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y-49.f, view.frame.size.width, view.frame.size.height)];
            }
            else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height-49.f)];
            }
        }
    } completion:^(BOOL finished) {
        //do smth after animation finishes
    }];
}

...这就是隐藏它的方式

... and this is how you hide it

- (void)hideTabBar:(UITabBarController *)tabbarcontroller
{
    [UIView animateWithDuration:kAnimationInterval animations:^{
        for (UIView *view in tabbarcontroller.view.subviews) {
            if ([view isKindOfClass:[UITabBar class]]) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y+49.f, view.frame.size.width, view.frame.size.height)];
            }
            else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height+49.f)];
            }
        }
    } completion:^(BOOL finished) {
        //do smth after animation finishes
        tabbarcontroller.tabBar.hidden = YES;
    }];
}

这篇关于iOS-如何使用动画隐藏/显示UITabBarController的标签栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆