如果你想从不同的视图控制器多次显示和隐藏你的标签栏,那么在你的 appDelegate.m 文件中实现下面的代码
- (void) hideTabBar:(UITabBarController *) tabbarcontroller
{
int height = 480;
if (([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
|| ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft))
{
height = 320;
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}
-(void) showTabBar:(UITabBarController *) tabbarcontroller
{
int height = 431;
if (([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
|| ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft))
{
height = 271;
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
for(UIView *view in tabbarcontroller.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
}
else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
}
}
[UIView commitAnimations];
}