手势冲突 UITableView 滑动删除 iOS [英] Gestures Conflict on UITableView swipe to delete iOS

查看:42
本文介绍了手势冲突 UITableView 滑动删除 iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的手势识别器有问题.我的目标是在我的表视图中使用滑动来删除.但我认为其他手势是相互冲突的.我正在使用这个库 romaonthego/REFrostedViewController 这是我的汉堡菜单库,并且该库具有 pangesture 功能.我认为冲突在于手势.因为当我在另一个项目中运行我的 tableview 代码时它正在工作.请帮忙,提前谢谢你.

I have a problem in my gesture recognizers. My goal is to implement using swipe to delete in my table view. But I think other gestures are conflicting with each other. I'm using this libray romaonthego/REFrostedViewController this a library for my hamburger menu and this library has a pangesture feature. I think the conflict is w/in the gestures. because when I run my code of my tableview in another project it's working.Pls help, Thank you in advance.

推荐答案

针对 iOS 11 更新

其他答案很有帮助,但就我而言,最好的解决方案是在 shouldRequireFailureOfOtherGesture 中执行逻辑,如下所示:

The other answers were helpful, but in my case the best solution was to do the logic in shouldRequireFailureOfOtherGesture like so:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if (gestureRecognizer == self.pan) {
        return YES;
    }
    return NO;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    if (gestureRecognizer == self.pan) {

        // iOS 10
        if ([NSStringFromClass([otherGestureRecognizer.view class]) isEqualToString:@"UITableViewWrapperView"]) {
            return YES;
        }
        // iOS 11
        else if ([otherGestureRecognizer isMemberOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer.view isKindOfClass:[UITableView class]]) {
            return YES;
        }
    }
    return NO;
}

在我的情况下,这有更好的行为.我还在平移手势上使用了 delaysTouchesBegan = YES.可能有用!

This had a much better behavior in my case. I also used delaysTouchesBegan = YES on my pan gesture. Might be useful!

这篇关于手势冲突 UITableView 滑动删除 iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆