本文介绍了如何将手势识别器从一个视图传递到另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个视图,其中包含几个子视图,这些子视图是带有多个按钮的复杂控件.超级视图具有用于点击,滑动等的手势识别器.
I have a view which contains several subviews which are complex controls with several buttons.The superview has gesture recognizers for taps, swipes etc.
在某些情况下,当我接收到一次或两次触摸时,我希望超级视图将手势识别器传递给子视图进行处理.
In some cases, when receiving a single or double touch I would like the superview to pass the gesture recognizer to the subview for treatment.
例如:
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
的自定义视图,然后覆盖:
Well, you could create a custom view inheriting from UIView
and then override:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
通过此方法,您可以返回要处理事件的视图.
From this method you can return the view you want to handle the event.
这篇关于如何将手势识别器从一个视图传递到另一个视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!