美文网首页
JXCategoryView左滑删除手势冲突解决方案

JXCategoryView左滑删除手势冲突解决方案

作者: Younggg | 来源:发表于2022-12-07 17:25 被阅读0次

1.自定义一个CustomScrollView;

- (instancetype)init
{
    self = [super init];
    if (self) {
        _isSimultaneouslyOpen = NO;
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openSimultaneous) name:kMessageMutiGestureOpenNoti object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeSimultaneous) name:kMessageMutiGestureCloseNoti object:nil];

    }
    return self;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return _isSimultaneouslyOpen;
}

- (void)openSimultaneous {
    _isSimultaneouslyOpen = YES;
}

- (void)closeSimultaneous {
    _isSimultaneouslyOpen = NO;
}

-(void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

2.在初始化JXCategoryView的VC.m中实现如下方法

- (Class)scrollViewClassInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return [CustomScrollView class];
}

3.在左滑所属的VC(定义为B) .m中viewWillAppear发出开启多手势响应通知

 [[NSNotificationCenter defaultCenter] postNotificationName:kMessageMutiGestureOpenNoti object:nil];

4.在左滑所属的VC.m (定义为B)中viewDidDisappear 以及B左右两边的(或者单边)的控制器VC的viewWillAppear中发出关闭多手势响应通知
5.以上处理后,还是会有滑动问题,需在控制器B中做以下处理,

///tableView滑动时,禁止父视图响应
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    
    UIScrollView *sr = (UIScrollView *) self.view.superview;
    if(sr && [sr respondsToSelector:@selector(panGestureRecognizer)]){
        sr.panGestureRecognizer.enabled = NO;
    }
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    UIScrollView *sr = (UIScrollView *) self.view.superview;
    if(sr && [sr respondsToSelector:@selector(panGestureRecognizer)]){
        sr.panGestureRecognizer.enabled = YES;
    }
}

相关文章

网友评论

      本文标题:JXCategoryView左滑删除手势冲突解决方案

      本文链接:https://www.haomeiwen.com/subject/pknnfdtx.html