iOS 滑动隐藏导航栏-三种方式

时间:2024-08-25 09:33:02

/** 1隐藏导航栏-简单- */
    self.navigationController.hidesBarsOnSwipe = YES;

/** 2隐藏导航栏-不随tableView滑动消失效果 */
//- (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){
//        //停止拖拽
//    }
//}

/** 3隐藏导航栏-手势脱离(加速)消失/出现 */
//- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
//    if (velocity.y > 0.0) {
//        [self.navigationController setNavigationBarHidden:YES animated:YES];
//    } else if (velocity.y < 0.0){
//        [self.navigationController setNavigationBarHidden:NO animated:YES];
//    }
//}