如何隐藏/显示UITabBarController的标签栏与animation?

我有一个关于iOS的UITabBarController的标签栏的问题。

我正在使用UITabBarController来显示一些视图,但我希望视图尽可能大的屏幕显示。 是否有可能隐藏标签栏,以便它通常不显示,直到用户触摸屏幕,然后标签栏将(与animation)显示在底部。 然后,几秒钟后,如果没有任何事情做,那么标签栏将再次消失,以便视图又回到全屏幕?

这是你如何显示它

 - (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 }]; } 

…这是你如何隐藏它

 - (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 7上隐藏标签栏并再次显示时,大小是错误的。 这段代码给出了更好的结果:

 - (void) toggleTabBar: (UITabBar *)tabBar view: (UIView*) view { tabBar.hidden = NO; [UIView animateWithDuration:0.5 animations:^{ if (hiddenTabBar) { tabBar.center = CGPointMake(tabBar.center.x, self.view.window.bounds.size.height-tabBar.bounds.size.height/2); } else { tabBar.center = CGPointMake(tabBar.center.x, self.view.window.bounds.size.height+tabBar.bounds.size.height); } } completion:^(BOOL finished) { hiddenTabBar = !hiddenTabBar; tabBar.hidden = hiddenTabBar; }]; } 

不要认为这将在苹果的UIGuidelines上起作用。 您使用的视图被绘制在标签栏之上,所以如果您将其淡入淡出,则不会出现任何内容。

你可以用button代替标签栏来做一个小视图。