iOS scrollView、tableView、UICollectionView判断滑动方向

CGFloat lastContentOffsetY;

//即将开始拖拽,记录滑动前的偏移量

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {

    lastContentOffset = scrollView.contentOffset.y;

}

//滑动过程中

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {

    if (scrollView.contentOffset.y < lastContentOffset)

    {

        [self.navigationController setNavigationBarHidden:NO animated:YES];//向上

    } else if (scrollView.contentOffset.y > lastContentOffset)

    {

        [self.navigationController setNavigationBarHidden:YES animated:YES];//向下

    }

}

你可能感兴趣的:(iOS scrollView、tableView、UICollectionView判断滑动方向)