【问题标题】:How to make the subview outside the bounds recognize the touches如何使边界外的子视图识别触摸
【发布时间】:2015-04-28 18:25:18
【问题描述】:

我有一个带有子视图的视图。当子视图中的一个按钮被点击时,子视图会扩展到视图的边界之外,并呈现几个其他按钮。但是,我找不到与他们互动的方法。

我在 Apple 的网站上找到了一个代码:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

// Convert the point to the target view's coordinate system.
// The target view isn't necessarily the immediate subview
CGPoint pointForTargetView = [self.targetView convertPoint:point fromView:self];

if (CGRectContainsPoint(self.targetView.bounds, pointForTargetView)) {

    // The target view may have its view hierarchy,
    // so call its hitTest method to return the right hit-test view
    return [self.targetView hitTest:pointForTargetView withEvent:event];
}

return [super hitTest:point withEvent:event];
}

但是,我不明白我应该如何使用它,以便我的子视图能够识别触摸。

任何帮助将不胜感激。

【问题讨论】:

    标签: ios uiview uigesturerecognizer


    【解决方案1】:

    您需要继承UIView 或您需要的任何类并覆盖该方法。然后创建该子类的对象并使用它。然后它会识别触摸。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-26
      • 2011-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多