我在 cellForRowAtIndexPath
UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom:)];[gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];[单元格 addGestureRecognizer:gestureR];它工作正常.但我想要 UISwipeGestureRecognizerDirectionLeft 所以像这样添加
[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)];当我检查方向和状态时,我总是得到 3 = 3
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {NSLog(@"%d = %d",recognizer.direction,recognizer.state);}如果我只应用一个手势,它就可以正常工作.我试图一个一个地添加两个手势.但它只会响应一个手势.
如何添加第二个手势.我直接将一个手势添加到 TableView 另一个手势到单元格,但现在使用.
试试这个
<上一页>UISwipeGestureRecognizer* 手势R;手势R = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];手势R.direction = UISwipeGestureRecognizerDirectionLeft;[查看 addGestureRecognizer:gestureR];手势R = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease];手势R.direction = UISwipeGestureRecognizerDirectionRight;//默认[查看 addGestureRecognizer:gestureR];如果您想处理左右滑动的不同功能,只需更改选择器即可.
I added this code in cellForRowAtIndexPath
UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:@selector(handleSwipeFrom:)];
[gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];
[cell addGestureRecognizer:gestureR];
it works fine. But I want UISwipeGestureRecognizerDirectionLeft so Added like this
[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)];
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.
How to add second gestures. I added directly to one gesture to TableView another one to cell but now use.
Try this
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.
这篇关于如何将滑动手势添加到 UITableView 单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何通过点击动画 UIImageview 以显示全屏?How to animate a UIImageview to display fullscreen by tapping on it?(如何通过点击动画 UIImageview 以显示全屏?)
停止 segue 并显示警报To stop segue and show alert(停止 segue 并显示警报)
iOS 5 故事板,以编程方式确定路径iOS 5 storyboard, programmatically determine path(iOS 5 故事板,以编程方式确定路径)
图标已经包含光泽效果Icon already includes gloss effects(图标已经包含光泽效果)
UIEdgeInsetsMake 是如何工作的?How does UIEdgeInsetsMake work?(UIEdgeInsetsMake 是如何工作的?)
UIProgressView 和自定义跟踪和进度图像(iOS 5 属性UIProgressView and Custom Track and Progress Images (iOS 5 properties)(UIProgressView 和自定义跟踪和进度图像(iOS 5 属性))