The main requirements are shown above.
1, through the custom ScrollView to achieve the panGesture proxy method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if ([gestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")] && [otherGestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")]) { return YES; } return NO; }Copy the code
Existing problems:
When a tableView or collectionView is embedded in a ScrollView, it will lose the bounce effect up and down and will not be able to pull down the refresh function
The solution is to package the collectionView in another scrollView and set scrollEnable to NO for the scrollView
2. Implement the – (of the outermost scrolLView and the inner CollectionView respectively.voidScrollViewDidScroll :(UIScrollView *)scrollView method to control the sliding time of inner and outer layers.
The outer scrollView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGPoint offset = scrollView.contentOffset; If (offset. Y <=0) {// ScrollView. contentOffset = CGPointZero; self.PK_canScroll = NO; } else if (offset.. y < = {_roofViewHeight) if (self. PK_homeCollectionView. ContentOffset. Y > 0) {/ / if the inner existence deviation, ContentOffset = CGPointMake(0, _roofViewHeight); self.PK_canScroll = NO; } else if (self PK_homeCollectionView. ContentOffset. Y < 0) {/ / if the inner existence deviation, Scrollview. contentOffset = CGPointMake(0, 0); self.PK_canScroll = NO; }else{self.PK_canScroll = YES; }}else{scrollView.contentOffset = CGPointMake(0, _roofViewHeight); self.PK_canScroll = NO; }}Copy the code
The inner collectionView
- (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGPoint offset = scrollView.contentOffset; If (self.pk_floorscrollView.pk_canscroll) {// The inner layer remains scrollView.contentOffset = CGPointZero; }else{// The outer layer is fixed, the outer layer is in the state of being pulled up to the maximum and pulled down to the maximum, the outer layer can not be pulled down when pulled up to the maximum; If (offset. Y >0) {// If (offset. Y >0) { The inner fixed the if (self. PK_floorScrollView. ContentOffset. Y = = 0) {scrollView. ContentOffset = CGPointZero; }}else{// Inner layer pull down, if outer layer pull up maximum state, The inner fixed the if (self. PK_floorScrollView. ContentOffset. Y > 0) {scrollView. ContentOffset = CGPointZero; }}}}Copy the code