- (void)scrollViewDidScroll:(UIScrollView *)scrollView { //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势 UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer; //获取到拖拽的速度 >0 向下拖动 <0 向上拖动 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]; }else if(velocity == 0){ //停止拖拽 }}复制代码