Cocoa -Touch: How do I know if there is a CGPoint in a specific CGRect?

I was wondering if there is an easy way to find out if there is a specific point in a specific CGRect?

I have this to find out where the user touched the screen:

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

No. I would like to know if this point is in the following rectangle:

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

Obviously, the following does not work:

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

I would be grateful for any help. Thank you very much!

+4
source share
2 answers

Use the CGRectContainsPoint function to determine if a point is inside the rectangle:

 if (CGRectContainsPoint(aFrame, currentPosition)) // Do something 
+11
source

All you need is a CGGeomery link , especially CGRectContainsPoint .

+2
source

All Articles