我已经在Stackoverflow中搜索过,无法找到SWRevealController和UIGestureRecognizer的特定组合的答案。
在我的iOS项目中,我添加了一个UIGestureRecognizer来打开像菜单一样的菜单。对于类似Facebook的菜单,我使用SWRevealController库:John-Lluch's SWRevealController library。
我还成功添加了带有
的UIGestureRecognizer[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
工作正常。现在我面临的问题是,我尝试删除此panGestureRecognizer,具体取决于用户是否登录。但是,以下两种情况似乎都不起作用:
[self.view removeGestureRecognizer:nil];
[self.view removeGestureRecognizer:self.revealViewController.panGestureRecognizer];
如何将其删除,请帮忙! (我希望我提供了足够的信息,否则请告诉我!谢谢!)
答案 0 :(得分:0)
for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
[self.view removeGestureRecognizer:recognizer];
}
答案 1 :(得分:0)
非常奇怪,我来到以下似乎有效的解决方案,感谢Karthik的提示。但是,我仍然认为它是次优的:
bool found = false;
for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers) {
if ([[NSString stringWithFormat:@"%@",[recognizer class]] isEqualToString:@"UIScrollViewDelayedTouchesBeganGestureRecognizer"]){
[self.view removeGestureRecognizer:recognizer];
found = true;
break;
}
}
if (!found && self.view.gestureRecognizers.count > 1) {
[self.view removeGestureRecognizer:self.revealViewController.panGestureRecognizer];
}
答案 2 :(得分:0)
下面的代码解决了我的问题,
while (myView.gestureRecognizers.count) {
[myView removeGestureRecognizer:[myView.gestureRecognizers objectAtIndex:0]];
}