【一步一步学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;
}
}