3 回答
TA贡献1799条经验 获得超8个赞
您可以将控制器或视图(以创建手势识别器的任何视图)设置为的委托UITapGestureRecognizer。然后在委托中您可以实现-gestureRecognizer:shouldReceiveTouch:。在您的实现中,您可以测试触摸是否属于您的新子视图,如果是,则指示手势识别器将其忽略。类似于以下内容:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
// test if our control subview is on-screen
if (self.controlSubview.superview != nil) {
if ([touch.view isDescendantOfView:self.controlSubview]) {
// we touched our control surface
return NO; // ignore the touch
}
}
return YES; // handle the touch
}
TA贡献2021条经验 获得超8个赞
作为Casey对Kevin Ballard的回答的跟进:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isKindOfClass:[UIControl class]]) {
// we touched a button, slider, or other UIControl
return NO; // ignore the touch
}
return YES; // handle the touch
}
基本上,这使所有用户输入类型的控件(例如按钮,滑块等)都能正常工作
- 3 回答
- 0 关注
- 767 浏览
添加回答
举报