美文网首页
iOS---实现上滑隐藏导航栏下拉显示导航栏效果

iOS---实现上滑隐藏导航栏下拉显示导航栏效果

作者: 彗星来的那一夜 | 来源:发表于2016-07-22 14:10 被阅读274次

    这个效果的关键点在于下方可供滑动的内容的偏移距离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;

    }

    }

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

    相关文章

      网友评论

          本文标题:iOS---实现上滑隐藏导航栏下拉显示导航栏效果

          本文链接:https://www.haomeiwen.com/subject/ndsijttx.html