UIPanGestures手势与UITableviewCell上滑动删除手势冲突

来源:互联网 发布:数据分析体系架构 编辑:程序博客网 时间:2024/05/17 04:00

UIPanGestures手势与UITableviewCell上滑动删除手势冲突

因为tableView是scrollView的子类,scrollView的滑动也是拖动产生的,你这样加,就把它原来的拖动手势给屏蔽了。这样处理:


1、添加手势代理,比如我这里的这个自定义的cell叫panCell。


@interface panCell : UITableViewCell<UIGestureRecognizerDelegate>



2、设置拖动手势的代理为panCell。


panCell的初始化函数中:


UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer allocinitWithTarget:self action:@selector(panAction:)];


pan.delegate = self;


[self addGestureRecognizer:pan];


3、添加手势代理函数:


以让当前手势和别的手势共存。返回YES为可以共存,返回NO为独占。


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer


{


    NSLog(@"当前手势:%@; 另一个手势:%@", gestureRecognizer, otherGestureRecognizer);


    return YES;


}


因为tableView是scrollView的子类,scrollView的滑动也是拖动产生的,它原来的拖动手势给屏蔽了。这样处理:


1、添加手势代理,自定义的cell叫panCell。


@interface panCell : UITableViewCell<UIGestureRecognizerDelegate>



2、设置拖动手势的代理为panCell。


panCell的初始化函数中:


UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer allocinitWithTarget:self action:@selector(panAction:)];


pan.delegate = self;


[self addGestureRecognizer:pan];


3、添加手势代理函数:


以让当前手势和别的手势共存。返回YES为可以共存,返回NO为独占。


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer


{


    NSLog(@"当前手势:%@; 另一个手势:%@", gestureRecognizer, otherGestureRecognizer);


    return YES;


}

0 0