3

I have a parent UIScrollView and a UICollectionView inside that UIScrollView. I want that UICollectionView scroll begins only when the parent UIScrollView reaches end of its scrolling. Can any one please help me for the same.

ChintaN -Maddy- Ramani
  • 5,156
  • 1
  • 27
  • 48
Saraswati
  • 1,516
  • 1
  • 14
  • 21

2 Answers2

1

In viewDidLoad, Disable Collectionview scroll.

self.collectionView.scrollEnabled = NO;

Now, Use Delegate of scrollview to detect bottom of the scroll view and than enable CollectionView scroll.

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    float bottomEdge = scrollView.contentOffset.y + scrollView.frame.size.height;
    if (bottomEdge >= scrollView.contentSize.height) {
       self.collectionView.scrollEnabled = YES;
    }
}

Hope it will work.

Chandan kumar
  • 1,074
  • 12
  • 31
0

Initially set the child scrollView yourScrollView.scrollEnabled = NO; also add tags to your scrollViews. 1 for parent and 2 for child preferably.

Get to know if you are at the bottom of the ScrollView using this code

-(void)scrollViewDidScroll: (UIScrollView*)scrollView
{
    if(scrollView.tag==1)
    {
    float scrollViewHeight = scrollView.frame.size.height;
    float scrollContentSizeHeight = scrollView.contentSize.height;
    float scrollOffset = scrollView.contentOffset.y;

    if (scrollOffset == 0)
    {
        // then we are at the top
    }
    else if (scrollOffset + scrollViewHeight == scrollContentSizeHeight)
    {
        //Handle Code to activate the child scrollView.
        // then we are at the end
    }
    }
}

Hope this helps. Happy Coding.

References SO Post

Community
  • 1
  • 1
Md. Ibrahim Hassan
  • 5,359
  • 1
  • 25
  • 45