假设标准配置(向上/向下),我想检测用户何时向上或向下滚动UIColletionView(这是UIScrollView的子类并符合UIScrollViewDelegate).我没有看到代表直接发现任何信息来检测这一点,尽管我可能已经在寻找一些东西了.
如果我知道用户正在滚动的方向,那么我可以使用这些UICollectionViewDatasource方法来确定是否应该从REST服务器加载更多数据,或者清除我已经拥有的管理固定内存空间的信息.
//如果向下滚动,则显示部分
- (UICollectionReusableView *)collectionView:(UICollectionView *)cv viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
//如果向下滚动,则节中的最后一个单元格正在消失
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
//如果向上滚动,则显示部分中的最后一个单元格
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//如果向上滚动,部分就会消失
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)view forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath{
解决方法
您可以检查UIScrollView(从哪个UICollectionView继承)panGestureRecognizer属性并执行以下操作:
CGPoint scrollVelocity = [collectionView.panGestureRecognizer velocityInView:collectionView.superview]; if (scrollVelocity.y > 0.0f) { NSLog(@"going down"); } else if (scrollVelocity.y < 0.0f) { NSLog(@"going up"); }
Swift 3.1:
let scrollVelocity = collectionView.panGestureRecognizer.velocityInView(collectionView.superview) if (scrollVelocity.y > 0.0) { print("going down") } else if (scrollVelocity.y < 0.0) { print("going up") }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。