在 parent class 的手势上使用 subclass 的手势

Using gesture of the subclass over the gesture of the parent class

我有一个 class MyView subclassing UIView 基本上是在整个视图中添加点击手势。

我还有一个 class MyViewWithTextField subclassing MyView。在这个视图中,有一个 UITextField 我添加了一个手势。

我的问题是,当我点击 UITextField 时,它的手势识别器的目标从未被调用,因为它是来自 parent 的手势识别器被调用的目标。

我试图在 MyViewpointInside:point:withEvent 方法中 return false 当水龙头在 UITextField 内部时,但它没有改变任何东西。

我该如何解决这个问题?

你可以试试 gesture.cancelsTouchesInView = NO;

您需要在子视图上设置 userInteractionEnabled,这样手势就不会在子视图上被忽略。

subviews.userInteractionEnabled = YES;