开发者

How to figure out that given point is inside the rectangle or not

i am working on app in which i want to draw an Rectangle.for draw a rectangle i have two CGRECT point.after draw a rectangle i have to pass a point and check whether the given point is lying inside the rectangle or not.can someone help me.Thanks

-(void)touchBeganAtPoint:(CGPoint)point{

    if (isDrawingCompleted) {        
        match = NSNotFound;

        for (NSInteger i = 0; i < [pointArray count]; i++)
        {
            NSValue *touchPointValue = [pointArray objectAtIndex:i];
            CGPoint currentPoint = [touchPointValue CGPointValue];
            CGRect controlPointRect = [self controlPointRectForPoint:currentPoint];

            if (CGRectContainsPoint(controlPointRect, point))
            {
      开发者_StackOverflow中文版          match = i;
                break;
            }
        }
    }
}

point is the variable which i have to check lie inside the rectangle which will make with two point store in point array.point array have always two point.


Use CGRectContainsPoint.

bool CGRectContainsPoint (
   CGRect rect,
   CGPoint point
);


Use CGRectContainsPoint function

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜