您的位置:首页 > 移动开发 > IOS开发

iOS使用push隐藏子页面底部bottom TabBar

2014-11-06 13:59 281 查看
以下两种情况是我在开发过程中遇到的,一种是代码使用pushViewController,另一种是storyboard直接使用push。之前也查阅了很多关于隐藏底部tabbar的资料,但是要么使用起来麻烦,要么就是藕合度高代码不规范(这里有点代码洁癖,当前类相关的事务应该写在本类中)。

1、使用pushViewController

如A->B;A是列表页,带有tabbar;B是内容页,不需要tabbar;

在A的事件中打开B,如下代码

-(void)showVideo:(EJAlbumModel *)model bySId:(NSString *)sid{
NSLog(@"%@",@"执行委托");
EJClassVideoViewController *videoController=[[EJClassVideoViewController alloc] init];
videoController.model=model;
videoController.semesterClassId=sid;
self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleBordered target:nil action:nil];// 修改下级页面的返回按钮,此处我是很想写到videoController中,但是backBarButtonItem的机制决定必须写在A中;
[self.navigationController pushViewController:videoController animated:YES];
}
在B的加载View视图事件initWithNibName中,加入
self.hidesBottomBarWhenPushed=YES;即可实现打开B隐藏tabbar,返回A重新现实tabbar;很简单吧

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.hidesBottomBarWhenPushed=YES;
}
return self;
}


2、使用storyboard

在storyboard中建立A和B,并使用ctrl+链接至B,即segue的打开方式;如下图所示:



此处只需要在可视化视图中修改B的一个属性即可(可惜很多技术文章都没提到这点,是因为我没有找到吗),如下图,选中B视图,并勾选Hide Bottom Bar on Push;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: