iOS之NavigationBar随滑动隐藏或显示

用UIScrollViewDelegate方法

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
    CGFloat velocity = [pan velocityInView:scrollView].y;
    if (velocity < -5) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    }else if(velocity > 5){
        [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
}

获取拖拽速度:velocity>0为向下拖拽, velocity<0为向上拖拽

posted @ 2017-01-18 12:21  YaoJinye  阅读(975)  评论(0编辑  收藏  举报