我有一个包含多个 subview 的 View ,这些 subview 是带有多个按钮的复杂控件。 super View 具有用于点击、滑动等的手势识别器。
在某些情况下,当接收到单次或双次触摸时,我希望父 View 将手势识别器传递给 subview 进行处理。
例如:
singletaprecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSingleTapGestureRecognizerDetected:)];
- (void)onSingleTapGestureRecognizerDetected:(UITapGestureRecognizer*)theTapGestureRecognizer
{
if (someCaseHappens) {
// do something with the gesture - for instance - move a control from one place to another or some other UI action in the superview
}
else {
// the subview will need to get the gesture and do something with it (imagine the touch was inside a button in a subview - the top superview should disregard the gesture and the button should be pressed) - THIS ISN"T HAPPENING NOW
}
}
最佳答案
那么,您可以创建一个继承自 UIView
的自定义 View ,然后覆盖:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
从这个方法你可以返回你想要处理事件的 View 。
关于ios - 如何将手势识别器从一个 View 传递到另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20889713/