How can I detect the scroll direction from the UICollectionView?

后端 未结 4 817
日久生厌
日久生厌 2020-12-09 17:52

I have a UICollectionView. I want to detect scroll direction. I have a two different animation style for scroll down and scroll up. So I must learn scroll direction.

4条回答
  •  隐瞒了意图╮
    2020-12-09 18:28

    Try this:

    Add this somewhere in you header:

    @property (nonatomic) CGFloat lastContentOffset;
    

    Then override the scrollViewDidScroll: method:

    #pragma mark - UIScrollViewDelegate
    
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (self.lastContentOffset > scrollView.contentOffset.y)
        {
            NSLog(@"Scrolling Up");
        }
        else if (self.lastContentOffset < scrollView.contentOffset.y)
        {
            NSLog(@"Scrolling Down");
        }
    
        self.lastContentOffset = scrollView.contentOffset.y;
    }
    

    Found in Finding the direction of scrolling in a UIScrollView?

提交回复
热议问题