Resolve the system sideslip return function conflict when uicollectionview slides horizontally

Time:2021-12-4

When sliding to the right, it conflicts with the horizontal sliding of uicollectionview. In the gap between holding the cell with a gesture, the page will return. The solution is as follows

1. Set uicollectionview.backgroundcolor to be empty or clearcolor.
UICollectionView.backgroundColor = [UIColor whiteColor]; 
2. If uicollectionview is installed in tableview, the backgroundColor of its parent view should also be set. It cannot be empty or clearcolor.
UITableView.backgroundColor = [UIColor whiteColor]; 
3. Since uicollectionview inherits from uiscrollview, make a gesture in uiscrollview and return to judgment processing. Add the classification uiscrollview + tzgesturerecognizer. H,

Classification can take effect when it is directly put into the item.
UIScrollView+TZGestureRecognizer.h

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UIScrollView (TZGestureRecognizer)

@end

NS_ASSUME_NONNULL_END

UIScrollView+TZGestureRecognizer.m

#import "UIScrollView+TZGestureRecognizer.h"


@implementation UIScrollView (TZGestureRecognizer)

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer {
    
    //First, judge whether the othergesturerecognizer is a system pop gesture
    if ([otherGestureRecognizer.view isKindOfClass:NSClassFromString(@"UILayoutContainerView")]) {
        
        //Then judge whether the state of the system gesture is began or fail,
        //At the same time, judge whether the position of Scrollview is just on the left
        if (otherGestureRecognizer.state == UIGestureRecognizerStateBegan && self.contentOffset.x == 0) {
            
            return YES;
        }
    }
    
    return NO;
}

@end

Note down the simplest solution known at present. If there is a better solution, please leave a message.

Recommended Today

The real problem of Alibaba IOS algorithm can’t hang up this time

More and more IOS developers continue to enter the peak of job hopping in 2020 Three main trends of interview in 2020: IOS bottom layer, algorithm, data structure and audio and video development Occupied the main battlefield. Data structure and algorithm interview, especially figure, has become the main reason for the failure of most first-line […]