ios判断某个坐标是否在某块区域内方法

来源:互联网 发布:微信矩阵怎么弄 编辑:程序博客网 时间:2024/05/21 09:10

实现有两种方法,//第一种是直接创建某一个区域,然后在判断是否在区域内,这种方法适合于任何图形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)) {}


0 0