由于本身用简书和知乎比较多,因此对其导航栏的效果比较好奇,本身私下里找资料实现了一下。这个效果的关键点在于下方可供滑动的内容的便宜距离inset的改变,以及滑动的scrollview代理的执行,废话很少说,上代码动画
首先是tableview的便宜距离inset的设置 if([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) { self.automaticallyAdjustsScrollViewInsets = NO; UIEdgeInsets insets = self.tableView.contentInset; insets.top =self.navigationController.navigationBar.bounds.size.height; self.tableView.contentInset =insets; self.tableView.scrollIndicatorInsets = insets; } self.tableView.frame =CGRectMake(0, 20, self.view.bounds.size.width, self.view.bounds.size.height);
上述代码的做用是在执行的时候自动改变tableview的便宜距离的相关设置,下一步在滑动的时候隐藏导航栏代理
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset { if(velocity.y>0) { self.navigationController.navigationBar.hidden = YES; } else { self.navigationController.navigationBar.hidden = NO; } }
由此便实现了简书和知乎的导航栏显示和隐藏的效果,各位能够自行添加动画。blog