检测iphone中绘制项目的触摸

时间:2013-06-20 07:27:59

标签: iphone ios cgcontext uitouch

如果我使用CGContext绘制圆圈,是否可以使用触摸拖动此圆圈。有没有办法检查触摸区域是否包含绘制的圆圈?

我想创建一个圆形或方框形状的自定义UIControl

1 个答案:

答案 0 :(得分:2)

你可以做的是制作那个圆圈的矩形

CGRect myRect=CGRectMake(center.x-radius, cemter.y-radius, 2r, 2r);

并通过选择触点来检测该矩形内的触摸

CGPoint touch=[[touches anyObject]locationInView:self];
 if(CGRectContainsPoint(myRect,touch ))
{

//code here for true condition
 }