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

标签 ios objective-c uigesturerecognizer uitouch

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

相关文章:

ios - 添加新行时 UITableView 停止滚动

swift - SpriteKit : detect if UILongPressGestureRecognizer tapped child node

ios - TableView 滚动问题与内容偏移

ios - 在 iPhone 应用程序中安全存储 Web API 凭据的位置?

ios - 使用 UIAlertViewStyleSecureTextinput 更改 UIImage

ios - 从 Storyboard 向 UILabel 属性字符串添加下划线失败

objective-c - 获取 UIGestureRecognizer 的 UITouch 对象

iphone - 使用 UISwipeGestureRecognizer 滑动 View

iphone - 如何找到一个月的特定日期?

ios - 使用 __IPHONE_OS_VERSION_MIN_REQUIRED 而不进行比较