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?

有帮助吗?

解决方案

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 {

        }
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top