Question: Scroll child scrollview only when parent scroll view reaches end


Scroll child scrollview only when parent scroll view reaches end

Answers 2
Added at 2017-01-04 11:01

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.

nr: #1 dodano: 2017-01-04 11:01

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.

nr: #2 dodano: 2017-01-04 11:01

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
    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

Source Show
◀ Wstecz