开发者

Cancel Tap gesture on UIBarbutton in iPhone

I have added Tap Gesture recognizer to a view. My view has an image and a UIToolBar at the bottom with a few UIBarbuttons I want to cancel any touches on these buttons. I am trying to use the following method to cancel the touch. How do I detect whether the touch is on the toolbar or any bar buttons? Frame is also not defined for Bar buttons...

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {


    if (gestureRecognizer == tapRecognizer) {
  if (touch.view==barbutton/*toolbar or bar button item*/) 
   {
   retu开发者_Python百科rn NO;   
  }

    }
    return YES;
}


CGPoint location = [touch locationInView:self.view];
if(CGRectContainsPoint(toolbar.frame, location)) { ... }

This is assuming the toolbar and self.view are in the same coordinate space. If not, you'll have to use UIView's coordinate conversion methods (convertPoint:toView:) to make the spaces match.


Buttons are the first responder and their uitouchup or other event will fire first and won't propogate to the backing view.

You can subclass your buttons and have the touchesbegan/moved/ended do:

[self.nextResponder touchesBegan:touches withEvent:event];

to have your backing view handle all their events for them in which case your gesture code should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜