在iPhone上隐藏选项卡栏
我在AppDelegate.m中使用以下代码创建了此UITabBar:在iPhone上隐藏选项卡栏,iphone,ios,objective-c,uitabbar,Iphone,Ios,Objective C,Uitabbar,我在AppDelegate.m中使用以下代码创建了此UITabBar: UITabBarController *tbc = [[UITabBarController alloc] init]; BarsViewController *bvc = [[BarsViewController alloc] init]; StopwatchViewController *svc = [[StopwatchViewController alloc] init]; TimerViewController
UITabBarController *tbc = [[UITabBarController alloc] init];
BarsViewController *bvc = [[BarsViewController alloc] init];
StopwatchViewController *svc = [[StopwatchViewController alloc] init];
TimerViewController *tvc = [[TimerViewController alloc] init];
[bvc.tabBarItem setTitle:@"Clock"];
[svc.tabBarItem setTitle:@"Stopwatch"];
[tvc.tabBarItem setTitle:@"Timer"];
[tbc setViewControllers:[NSArray arrayWithObjects:svc, bvc, tvc, nil] animated:YES];
[tbc setSelectedIndex:1];
我想有标签栏完全隐藏,而不是推上屏幕上的任何层。有什么方法可以做到这一点吗?在您的第一个viewcontroller中添加此选项
-(void)viewWillAppear:(BOOL)animated{
self.tabBarController.tabBar.hidden = YES;
}
如果您想从不同的视图控制器多次显示和隐藏选项卡栏,请在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];
}
这不管用;选项卡栏没有消失,所有内容都向上推,在底部留下一个黑色栏。在所需的viewController[appDelegate hideTabBar:appDelegate.tbc]处调用此选项;它工作得很好,我刚刚检查过,如果您在iphone 5中运行此代码,然后相应地设置帧,如使用568而不是480 ok。所以只需使用您的tabbar控制器名称。tabbar.hidden=true;。那你为什么要创造它?