UITabBar动态的隐藏和显示

来源:互联网 发布:北邮图书馆软件 编辑:程序博客网 时间:2024/05/29 04:45

#import <UIKit/UIKit.h>

//继承UITabBarController类,实现UITabBar的收缩

@interface UITabBarController (ShowHideBar)


- (void)hideTabBar;

- (void)showTabBar;


@end



#import "UITabBarController+ShowHideBar.h"

#import "Definition.h"

@implementation UITabBarController (ShowHideBar)


- (void)hideTabBar

{

    

    for(UIView *view inself.view.subviews)

    {

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

        {

            [UIView beginAnimations:nil context:NULL];

            [UIView setAnimationDuration:0.3];

            [view setFrame:CGRectMake(view.frame.origin.x, ScreenHeight, view.frame.size.width,

                                      view.frame.size.height)];

            [UIView commitAnimations];

        }

        else

        {

            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y,

                                      view.frame.size.width, ScreenHeight)];

        }

    }

}


- (void)showTabBar

{

    

    for(UIView *view inself.view.subviews)

    {

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

        {

            [UIView beginAnimations:nil context:NULL];

            [UIView setAnimationDuration:0.3];

            

            [view setFrame:CGRectMake(view.frame.origin.x, ScreenHeight-49, view.frame.size.width,

                                      view.frame.size.height)];

            [UIView commitAnimations];

        }

        else

        {

            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y,

                                      view.frame.size.width, ScreenHeight-49)];

        }

    }

}


@end


原创粉丝点击