UICollectionView in UIScrollView -> Scroll Order

2019-05-31 05:40发布

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?

1条回答
Anthone
2楼-- · 2019-05-31 06:08

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 {

        }
    }
查看更多
登录 后发表回答