0
votes

I have view controller which has one horizontal collection view which has three cells. Inside each cell I have one vertical collection view which has 2 section. 1st section has one cell and 2 nd section is Dynamics It can have any number of cells. In first section of vertical collection view which has one cell it has one horizontal collection view which can have any number of cells.

Issue : when innermost collection view which is inside first section of vertical collection view is scrolling, and when it reaches end of collection view I want to disable the scrolling so that my outer most collection view which has three cells can scroll, and immediately after that I want to enable the scrolling of innermost collection view. So that it can scroll again. It's like scroll view or collection view

Nested Collection View

1
When you say disabling the scrolling, do you mean disabling the scrolling both ways(left to right and right to left) ?Pooja Kamath
can you please share the screen shot what exactly you need.VDPurohit
@pooja Yes. I need it to stop working when I reach at the last cell of gray collection view, If I stop scrolling of inner collection view it will automatically scroll to next cell of outer collection view(Red). But I want event Which recognise last cell. and when it stop it will scroll to next but after reaching to next cell of red collection view I want to enable the scrolling of grey collection viewMehul Makwana
@VDPurohit . Please check screens shotMehul Makwana

1 Answers

0
votes

enter image description here

Here is a similar example ,which has collection view within another collection view cell

GitHub sample

Here I am trying to get the last cell displayed event in the inner collection view and disabling the scroll.

override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
        //Checking if its not the inner collection view
        if(collectionView.restorationIdentifier != "Collection")
        {
            //scrolled till datasource.count -1 == 14 in our case
            if( indexPath.row == 14){

                //Disabling the scrolling
                collectionView.isScrollEnabled = false;

                //Saved the collection view , so that the scrolling can be enabled later.
                scrolldisabledCollectionView = collectionView;
            }
        }

    }

And when the outer collection view is scrolled, The inner collection view is enabled.

 override func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
    {
        if(collectionView?.restorationIdentifier == "Collection")
        {
            scrolldisabledCollectionView?.isScrollEnabled = true
        }
    }