1

Is it possible to cancel a UIGestureRecognizer when I tap on a button?

4

3 回答 3

8
- (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
}
于 2013-04-19T07:37:26.850 回答
0

试试这个方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

return whateverYouWant;
} 
于 2013-04-19T07:43:24.953 回答
0

是的你可以。您可以通过此代码添加和删除它。

-(IBAction) YourButtonAction {
  some code, that your button must to do
  self.yourButton removeGestureRecognizer: (yourRecognizer);
}
于 2013-04-19T07:58:18.397 回答