0

我有一个 UIView,我正在基于 touchesBegan 和 touchesMoved 渲染一个 UIBezierPath。但我只想在 UIVIew 内的某个区域绘制。我想在仅注册触摸的 UIView 中设置一个 CGRect 。此区域之外的任何触摸都不会被注册。

理想情况下,如果用户拖到这个矩形之外,他们可以保持触摸,但是当他们拖回该区域时会调用 touchesBegan 方法。

有人能帮忙吗?谢谢。

4

2 回答 2

1

使用 pointInside:withEvent: 告诉它在该区域之外不接受该点。

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    return [self isPointWithinMyBounds:point];
}

- (BOOL) isPointWithinMyBounds:(CGPoint) point{
    //determine if the point is within the rect
    return NO;
}

touchesMoved 事件将是复杂事件。您只会在视图之外停止绘图。

但这应该可以达到您想要的效果。

于 2012-06-22T21:01:38.317 回答
0

您可以在当前的 UIView 之上放置一个不可见的 UIView,其大小与您预期的触摸区域相同。然后只需将手势识别器添加到该视图即可。

于 2012-06-22T20:57:12.667 回答