gestureRecognizer:shouldReceiveTouch:实现失败

时间:2012-06-26 17:16:24

标签: iphone objective-c ios ipad

如果触摸的视图属于某些类(即UIButtonUIBarButtonItem),我试图忽略我的gestureRecognizer:

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

  NSLog(@"%@", touch.view);

  if ([touch.view isKindOfClass:[UIButton class]]){
    return NO;
  } else if ([touch.view isKindOfClass:[UIBarButtonItem class]]){
    return NO;
  }
  return YES; // handle the touch
}

这对UIButton非常有用。它不适用于UIBarButtonItem。触摸UIBarButtonItem时的我的NSLog结果是:

<UIToolbarTextButton: 0x7b8f500; frame = (4 0; 60 40); opaque = NO; layer = <CALayer: 0x7b8f900>> 2012-06-26 12:09:48.021 

我尝试将[UIBarButtonItem class]更改为[UIToolBarTextButton class],但由于这是一个未记录的类,我无法做到。还有其他办法吗?

感谢。

1 个答案:

答案 0 :(得分:0)

如果您的UIBarButtonItem位于UINavigationBar中,那么您需要继承UINavigationBar并实现另一个

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

以捕获UIBarButtonItem的手势。可能还有其他方法可以实现这一目标。