因为自己用简书和知乎比较多,所以对其导航栏的效果比较好奇,自己私下里找资料实现了一下。这个效果的关键点在于下方可供滑动的内容的便宜距离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;
    }
}

 由此便实现了简书和知乎的导航栏显示和隐藏的效果,各位可以自行添加动画。

相关文章:

  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
  • 2021-07-31
  • 2021-12-04
相关资源
相似解决方案