[英]How do I detect a touch over a specific area
目前我看到触摸事件将向我显示触摸发生的UIView。 但是,如果我需要检测一些非矩形形状的触摸,如圆形。 我该怎么做呢?
基本上我只想在用户触摸不可见的圆形区域内的某个地方时才做某事。
任何帮助/方向表示赞赏,TIA!
你会这样做的。 请注意,'locationInView'将返回相对于指定视图的触摸坐标,因此无论视图在屏幕上的哪个位置,视图左上角的触摸都将返回(0,0)。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
// gets the coordinats of the touch with respect to the specified view.
CGPoint touchPoint = [touch locationInView:self];
// test the coordinates however you wish,
...
}
要测试球体,您将计算从触摸点到球体中心的距离,然后检查这是否小于球体半径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.