iOS - 忽略点击手势
我在自定义表格单元格中有一个 UITapGestureRecognizer,它不执行任何操作(删除点击单元格来选择它的功能)。这非常有效,但是单元格中有一些按钮(子视图)无法点击,因为点击手势处理整个单元格区域。
因此,它就像检测触摸手势何时位于这些按钮之一上并返回 false 以取消该特定手势一样简单,对吗?好吧,不适合我......
我已经删除了逻辑,只是在手势识别器中返回“否”,但我仍然无法点击按钮。
- (BOOL)ignoreTap:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch
{
return NO;
}
我在这里缺少什么吗?
I have a UITapGestureRecognizer in a custom table cell which is intended to do nothing (remove the ability to tap on a cell to select it). This works great however there are some buttons (subviews) in the cell which cannot be tapped because the tap gesture handles that whole cell area.
So its as simple as detecting when the touch gesture is over one of those buttons and returning false to cancel that particular gesture, right? Well not for me ...
I have removed the logic and simply returned NO in the gesture recogniser, but I still can't tap the buttons.
- (BOOL)ignoreTap:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch
{
return NO;
}
Is there something I am missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案更简单:您不应该使用手势识别器来执行此操作。如果您不希望单元格可选,可以执行以下两件事:
-tableView:willSelectRowAtIndexPath:
使其不可选择,selectionStyle
为UITableViewCellSelectionStyleNone
以删除突出显示效果这样做应该保留您的按钮功能。
编辑:如果你不想这样做,那么你可以做你最初尝试的事情 - 除非我认为你的方法名称错误,它应该是这样的:
The solution is more simple: you shouldn't be using a gesture recognizer to do this. If you don't want a cell to be selectable, you can do two things:
nil
from-tableView:willSelectRowAtIndexPath:
to make it unselectableselectionStyle
toUITableViewCellSelectionStyleNone
to remove the highlight effectDoing it this way should preserve your button functionality.
Edit: if you don't want to do that, then you can do what you were originally trying — except I think you have the method name wrong, it should be this:
为此,我制作了一个如下所示的自定义按钮:
to do this, I made a custom button like this: