实现有两种方法,
//第一种是直接创建某一个区域,然后在判断是否在区域内,这种方法适合于任何图形
CGMutablePathRef pathRef =CGPathCreateMutable();
CGPathMoveToPoint(pathRef,NULL, p.x-itemWidth/2, p.y);
CGPathAddLineToPoint(pathRef,NULL, p.x-itemWidth/2, p.y);
CGPathAddLineToPoint(pathRef,NULL, p.x-itemWidth/2,_axisHeight + _margin);
CGPathAddLineToPoint(pathRef,NULL, p.x+itemWidth/2,_axisHeight + _margin);
CGPathAddLineToPoint(pathRef,NULL, p.x+itemWidth/2, p.y);
CGPathCloseSubpath(pathRef);
if(CGPathContainsPoint(pathRef,NULL, p, NO)){
}
//第二种是直接判断是否在指定四方形区域内,这种方法只能是矩形范围内
if (CGRectContainsPoint(CGRectMake(p.x-itemWidth/2,0, itemWidth, _axisHeight +_margin), curPoint)) {
}版权声明:本文为wangtianya125原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。