【一步一步学IOS5 】 如何在导航界面隐藏TabBar

前面的例子中,我们开发了一个tab bar(选项卡栏)应用程序。

 

我们将导航控制器嵌入在tab bar控制器内。因此,当用户轻拍任一菜单项时,导航控制器切换到详细视图。

 


但是tab bar 在详细视图时,仍然占用了一些屏幕空间,我们需要隐藏tab bar,释放更多的屏幕空间。

 

1. UIViewController 类 的hidesBottomBarWhenPushed属性

 

在UIViewController  中有一个属性:hidesBottomBarWhenPushed, 它是一个Boolean 值,表示屏幕底部的toolbar 是否隐藏

 

当设置为YES 时,在Navigation 控制器内的视图控制器,会隐藏tab bar

 

2.仅需添加一行代码

 

在我们Tab Bar 应用程序中,我们仅需在prepareForSegue:方法中添加一行代码,设置RecipeDetailViewController的hidesBottomBarWhenPushed 属性为YES。

 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

    if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {

 

        NSIndexPath *indexPath = nil;

 

        RecipeDetailViewController *destViewController = segue.destinationViewController;

        if ([self.searchDisplayController isActive]) {

            indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];

            destViewController.recipeName = [searchResults objectAtIndex:indexPath.row];

        }else{

            indexPath = [self.tableView indexPathForSelectedRow];

            destViewController.recipeName = [recipes objectAtIndex:indexPath.row];

        }

 

        //Hide bottom tab bar in the detail view

        destViewController.hidesBottomBarWhenPushed = YES;

 

    }

}



保存更新,运行App,当详细视图显示时,tab bar 应该会隐藏了。



 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值