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

下面两种情况是我在开发过程中遇到的,一种是代码使用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];// 改动下级页面的返回button,此处我是非常想写到videoController中,可是backBarButtonItem的机制决定必须写在A中;
[self.navigationController pushViewController:videoController animated:YES];
}
在B的载入View视图事件initWithNibName中。增加 self.hidesBottomBarWhenPushed=YES;就可以实现打开B隐藏tabbar。返回A又一次现实tabbar。非常easy吧

- (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;



posted @ 2017-06-07 16:15  claireyuancy  阅读(1157)  评论(0编辑  收藏  举报