How can I detect the scroll direction from the UICollectionView?

后端 未结 4 841
日久生厌
日久生厌 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:32

    this is the best way to get scroll direction, hope this helps you

    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
    
        CGPoint targetPoint = *targetContentOffset;
        CGPoint currentPoint = scrollView.contentOffset;
    
        if (targetPoint.y > currentPoint.y) {
            NSLog(@"up");
        }
        else {
            NSLog(@"down");
        }
    }
    

提交回复
热议问题