一个scrollview上有几个按钮
在scrollview上add 了一个单击事件
singletap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[singletap setNumberOfTapsRequired:1];
[scrollview addGestureRecognizer:singletap];
这样点击按钮,不会响应按钮的事件,直接跳到handleSingleTap去了?
单击事件不是应该先被直接单击的subview处理,如果没有处理才提交到supview处理嘛?
怎么才能让按钮响应单击事件?
使用
UIGestureRecognizerDelegate的一个方法判断点击的是哪个view,确定是否响应事件。
singletap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[singletap setNumberOfTapsRequired:1];
singletap.delegate = self;
[scrollview addGestureRecognizer:singletap];
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if(touch.view != scrollview){
return NO;
}else
return YES;
}