Delegating just scroll events in UICollectionView inside ScrollView Swift

349 views Asked by At

I have a ABCController that including UIPageViewController and this controller including 3 different controllers that connected to tabs.

In first controller that connect to UIPageViewController there is CollectionView that delegated to it's own controller and I'm using of UICollectionViewDelegateFlowLayout to shape cells.

But when I change delegate controller in ABCController to it self (to make syncScroll with mainScroll)

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

stops working because I delegated collectionview to another controller.

Is there any way to just delegate scroll events to another controller?

I know that it may little complex but I hope to find a way.

1

There are 1 answers

0
nghiahoang On

you could do it by create a wrapper:

class CollectionViewController: UICollectionViewDelegate, UICollectionViewDatasource {
    var scrollDelegate: UIScrollViewDelegate?

    // delegate scroll events
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
       scrollDelegate?.scrollViewDidScroll(scrollView)
    }
    
    // other events
}