János
János

Reputation: 35114

collectionView does not scroll when few item exist

I want to get collectionView scroll even though only 2 items are contained in it. I want to implement UIRefreshControl when pulling it. Any idea why it does not move?

enter image description here

Upvotes: 0

Views: 163

Answers (1)

József Vesza
József Vesza

Reputation: 4795

Scroll views only scroll, if their content size is bigger then the currently visible frame.

You can still implement pull-to-refresh without using UIRefreshControl, you just have to observe user's scroll event. The basic workflow is this:

  • Add your "refresh control" (a simple view) above your collection view
  • Implement the scrollViewDidEndDragging(_:willDecelerate:) delegate method to check the content offset
  • If the content offset is greater than a pre-defined value (let's say 40 points), you trigger the refreshing code

This article contains a full example, check it out!

Upvotes: 1

Related Questions