Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa-Touch: How to find out if CGPoint is in a certain CGRect?

I was wondering if there is a simple way to find out if a certain point is in a certain CGRect?

I have this to get the position of where the user touched the screen:

UITouch *touch = [touches anyObject];    
CGPoint currentPosition = [touch locationInView:self.view];

No I would like to find out if this point is in the following rect:

CGRect aFrame = CGRectMake(0, 100, 320, 200);

The following does obviously not work:

if (currentPosition = aFrame) {//do something}

I'd be grateful for any help. Thanks a lot!

like image 543
n.evermind Avatar asked Dec 13 '22 13:12

n.evermind


1 Answers

Use CGRectContainsPoint function to determine if point lies inside a rectangle:

if (CGRectContainsPoint(aFrame, currentPosition))
   // Do something
like image 101
Vladimir Avatar answered Jan 25 '23 01:01

Vladimir