How to add Swipe Gestures to UITableView cell?(如何将滑动手势添加到 UITableView 单元格?)
问题描述
我在 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 单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将滑动手势添加到 UITableView 单元格?


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01