scrolling not working in UICollectionView

I am using the lastest IOS Swift. I have a UICollectionView in my ViewController. I load photos in that collection view. But the photos loaded go beyond the height of the controller and there is no way to scroll up. I checked Vertical Scroll direction in UICollectionView but is still not scrolling. Any help will be appreciated.

Replies

Did you make the scrollview taller than the view that contains it?

Post not yet marked as solved Up vote reply of KMT Down vote reply of KMT

You are correct that UICollectionView can manage the scrolling and do not need a UIScrollView

You need to add the protocol UICollectionViewDelegateFlowLayout to your ViewController and then implement


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize


which tells the collectionView the appropriate sizes for your cells. Once this has been implemented, the scrolling that you were expecting is handled.


You may also need to checkout/implement:


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets


as the storyboard settings seem to be ignored when you have implemented the delegate.

KMT's Reply helped me a lot Thanks so much! @KMT