Pull-to-refresh in UICollectionViewController

后端 未结 5 987
闹比i
闹比i 2021-01-29 19:06

I want to implement pull-down-to-refresh in a UICollectionViewController under iOS 6. This was easy to achieve with a UITableViewController, like so:

5条回答
  •  猫巷女王i
    2021-01-29 19:43

    mjh's answer is correct.

    I ran into the issue where if the the collectionView.contentSize was not larger then the collectionView.frame.size, you can not get the collectionView to scroll. You can not set the contentSize property either (at least I couldn't).

    If it can't scroll, it won't let you do the pull to refresh.

    My solution was to subclass UICollectionViewFlowLayout and overide the method:

    - (CGSize)collectionViewContentSize
    {
        CGFloat height = [super collectionViewContentSize].height;
    
        // Always returns a contentSize larger then frame so it can scroll and UIRefreshControl will work
        if (height < self.collectionView.bounds.size.height) {
            height = self.collectionView.bounds.size.height + 1;
        }
    
        return CGSizeMake([super collectionViewContentSize].width, height);
    }
    

提交回复
热议问题