点击按钮时取消 UIGestureRecognizer?
Posted
技术标签:
【中文标题】点击按钮时取消 UIGestureRecognizer?【英文标题】:Cancel UIGestureRecognizer when a button is tapped? 【发布时间】:2013-04-19 07:33:13 【问题描述】:点击按钮时是否可以取消UIGestureRecognizer
?
【问题讨论】:
为什么不呢?但是让你的问题更清楚 “取消”是什么意思?更具体/更清晰。 【参考方案1】:- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
// test if our control subview is on-screen
if([gestureRecognizer isMemberOfClass:[UITapGestureRecognizer class]])
if ([touch.view isKindOfClass:[UIButton class]])
return NO; // ignore the touch
return YES; // handle the touch
【讨论】:
这不会取消识别器,只是忽略按钮触摸。【参考方案2】:试试这个方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
return whateverYouWant;
【讨论】:
【参考方案3】:是的,你可以。您可以通过此代码添加和删除它。
-(IBAction) YourButtonAction
some code, that your button must to do
self.yourButton removeGestureRecognizer: (yourRecognizer);
【讨论】:
以上是关于点击按钮时取消 UIGestureRecognizer?的主要内容,如果未能解决你的问题,请参考以下文章
UISearchController 在点击取消按钮时关闭 VC