UIGestureRecongnizer 手势拦截

时间:2023-03-08 22:32:45

在一个scrollview添加了一个tap的手势事件,然后在scrollview上添加了几个Button,在ios6,ios7 中两个点击事件相安无事,但在ios5中按钮却无法点击,究其原因是因为在ios5中tap手势拦截了button的点击事件,解决方法如下:

1.给手势设置代理

2.在下面的方法中,如果是UIButton的点击就阻止手势的点击事件。

// called before touchesBegan:withEvent: is called on the gesture recognizer for a new touch. return NO to prevent the gesture recognizer from seeing this touch

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

{

if([touch.view iskindOfclass [UIButton class]]

{

return No;

}

return YES;

}

不过目前应该不必用到这个了,因为iOS6现在都被淘汰了,更不用说iOS5啦