目前我看到一个触摸事件会显示触摸发生的UIView。但是如果我需要检测某些非矩形形状的触摸,比如一个圆形,该怎么办?
基本上,我只想在用户触摸不可见的圆形区域内做一些事情。
任何帮助/指导都将不胜感激,谢谢!
目前我看到一个触摸事件会显示触摸发生的UIView。但是如果我需要检测某些非矩形形状的触摸,比如一个圆形,该怎么办?
基本上,我只想在用户触摸不可见的圆形区域内做一些事情。
任何帮助/指导都将不胜感激,谢谢!
-(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,
...
}
要针对一个球进行测试,您需要计算触摸点到球心的距离,然后检查这是否小于球半径。