[英]UIGestureRecogniser on a masked UIView?
有没有办法知道“点击”是否在UIView的屏蔽区域内部或外部? 我正在使用CoreGraphics掩盖UIView。
到目前为止我的代码是这样的..
- (void)viewDidLoad {
UIGestureRecogniser *r = [[UIGestureRecogniser alloc] initWithTarget:self action:@selector(gestCall:)];
[self addGestureRecogniser:r];
}
- (void)gestCall:(UIGestureRecogniser *)gestRec {
if ("somthing") {
// outside of mask
} else {
// inside of mask
}
}
谢谢。
我终于找到了我想要的解决方案。 因此,为了任何一个试图找到的人的利益是CGPoint在任何CGPath内。
这很简单。
UIBezierPath *p = [UIBezierPath bezierPathWithCGPath:anyCGPath];
BOOL isInPath = [p containsPoint:anyCGPoint];
基本上,您需要检查触摸坐标并确定是否落入遮罩区域。 覆盖hitTest:withEvent:
和帐户图像掩码。 您可以在被覆盖的` - [UIView hitTest:withEvent:]中使用[[[self layer] presentationLayer] hitTest:aPoint]
或[[[self layer] mask] hitTest:aPoint]
]。
[编辑]
检查在CGPath附近点击的用户是否有助于查找问题的答案。
[编辑]
请在您的手势处理程序中进行以下操作,以确定是否处理水龙头。
point.x*point.x+point.y*point.y
(圆公式),此值必须小于或等于半径的平方即radius*radius
。 如果满足此条件,则您的分接点位于圆圈内,否则在外部。 希望能说清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.