gpt4 book ai didi

ios - 如何将手势识别器从一个 View 传递到另一个 View

转载 作者:可可西里 更新时间:2023-11-01 03:30:40 32 4
gpt4 key购买 nike

我有一个包含多个 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 。

看看:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/hitTest:withEvent :

关于ios - 如何将手势识别器从一个 View 传递到另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20889713/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com