当你程序的view使用了手势UIGestureRecognizer,而你在这个view上面又添加了按钮,那么按钮的响应回调事件方法是不会被调用的,但是按钮是可以看到被按下的高亮效果。(ios4,ios5的bug,ios6就没有了)
因为 根据响应链来看,这个view上的所有触摸事件都被手势给吸收了,所以要解决这个bug,要给这个手势代理加一些事件过滤,对button事件就不要拦截独吞了。代码如下:
- (void)addGestureRecognizer{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(hiddenKeyboard)];
tap.delegate = self;
self.gestureOfHiddenKeyboard = tap;
[self.view addGestureRecognizer:tap];
[tap release];
}
#pragma mark UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isMemberOfClass:[UIButton class]]) {
//放过button点击拦截
return NO;
}else{
return YES;
}
}