Question

I have a UICollectionView inside a UIScrollView.

My plan is, if the UICollectionView reached the Top or Bottom the outer ScrollView gets the scroll gestures. If the outer ScrollView reached the Top or the Bottom, the CollectionView gets the gestures.

How can I do it?

Was it helpful?

Solution

Okay, here is my Solution in some words:

  1. -Observe the contentOffset of both ScrollViews
  2. -Check when the inner scrollView reach the top or bottom
  3. -Disable the Scroll from the inner Scrollview
  4. -Enable the Scroll from the outer Scrollview
  5. -Check when the outer scrollView reach the top or bottom
  6. -Disable the Scroll from the outer Scrollview
  7. -Enable the Scroll from the inner Scrollview

very simple! Observe the contentOffset like this:

[self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];

this methode get called:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        if ([keyPath isEqualToString:@"contentOffset"]) {

        } else {

        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top