Gestures添加到UITableView单元格

Gestures添加到UITableView单元格

本文介绍了如何将Swipe Gestures添加到UITableView单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此代码添加到 cellForRowAtIndexPath

UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]
                                             initWithTarget:self action:@selector(handleSwipeFrom:)];
        [gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];
        [cell addGestureRecognizer:gestureR];

一切正常。但是我想 UISwipeGestureRecognizerDirectionLeft 所以像这样添加

it works fine. But I want UISwipeGestureRecognizerDirectionLeft so Added like this

[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)];

当我检查方向和状态时,我总是得到3 = 3

When I check with direction and state I am always getting 3 = 3

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {

    NSLog(@"%d = %d",recognizer.direction,recognizer.state);
}

如果我只申请一个手势就行了。我试着逐个添加两个手势。但它只会响应一个手势。

if I apply only one Gesture it works fine. I tried to add two gestures one by one. but it will responding for only one gesture.

如何添加第二个手势。我直接添加了一个手势给TableView另一个手机,但现在使用。

How to add second gestures. I added directly to one gesture to TableView another one to cell but now use.

推荐答案

试试这个


UISwipeGestureRecognizer* gestureR;
gestureR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];
gestureR.direction = UISwipeGestureRecognizerDirectionLeft;
[view addGestureRecognizer:gestureR];

gestureR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];
gestureR.direction = UISwipeGestureRecognizerDirectionRight; // default
[view addGestureRecognizer:gestureR];

如果你想在左右滑动中处理不同的功能,只需更改选择器。

If you want to handle different functionalities on left and right swipes, just change the selectors.

这篇关于如何将Swipe Gestures添加到UITableView单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 18:01