简体   繁体   English

在editmode中如何在UITableViewCell上暂停/禁用UILongPressGestureRecognizer

[英]How to pause/disable UILongPressGestureRecognizer on a UITableViewCell while in editmode

In a tableview I have on every cell a UILongPressGestureRecognizer which I add like this: 在tableview中,我在每个单元格上都有一个UILongPressGestureRecognizer ,我这样添加:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] 
                                          initWithTarget:self 
                                          action:@selector(TableCellLongPressed:)];
longPress.minimumPressDuration = 0.5f;
[cell addGestureRecognizer:longPress];
[longPress release];

Now I do have the following problem I want the user to be able to rearrange the cell in the tableview so I have a button that sets the tableView to EditMode like this: 现在我确实有以下问题我希望用户能够重新排列tableview中的单元格,所以我有一个按钮,将tableView设置为EditMode,如下所示:

[self.myTableView setEditing:!self.myTableView.editing animated:YES];

Now when the user tries to drag a cell and does not drag it far enough the longPress fires his action which is very annoying for the user cause another view gets pushed. 现在当用户试图拖动一个单元并且没有将它拖得足够远时,longPress会激活他的动作,这对用户来说非常烦人,导致另一个视图被推动。 How can I pause or disable the UILongPressGestureRecognizer when the tableView is in EditMode? 当tableView在EditMode中时,如何暂停或禁用UILongPressGestureRecognizer

You should implement the UIGestureRecognizerDelegate delegate for this method: 您应该为此方法实现UIGestureRecognizerDelegate委托:

gestureRecognizer:shouldReceiveTouch: gestureRecognizer:shouldReceiveTouch:

In the method, check if you're editing the table and return NO if you are. 在该方法中,检查您是否正在编辑表,如果是,则返回NO。

Tim 蒂姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM