【问题标题】:UIView only accept touches in certain areaUIView 只接受特定区域的触摸
【发布时间】:2012-06-22 20:55:01
【问题描述】:

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

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

有人可以帮忙吗?谢谢。

【问题讨论】:

    标签: iphone ios cocoa-touch ipad uiview


    【解决方案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 事件将是复杂事件。你只会在视图之外停止绘图。

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多