I have a simple screen in my iPhone app where I want a 320x100 rectangle at the bottom of the screen to capture a touch. Here is my code inside touchesBegan:withEvent:
for (UITouch *touch in touches) {
CGPoint touchPoint = [touch locationInView:self.view];
NSLog(@"touch @ %f, %f", touchPoint.x, touchPoint.y);
CGRect rectangle = CGRectMake(0, 480, 320, 100);
NSLog(@"midX, midY = %f, %f", CGRectGetMidX(rectangle), CGRectGetMidY(rectangle));
if (CGRectContainsPoint(rectangle, touchPoint)) {
NSLog(@"You touched inside the rectangle.");
}
}
Now this code is not working properly ... a log from the midpoint of the rectangle shows that my rectangle is built in midX, midY = 160.000000, 530.000000. According to the CGPoint documentation, the origin (0, 480)is the bottom left corner, but it acts like the origin is the top left corner.
When I change the beginning of my rectangle to 0, 380, everything works as intended. Maybe this morning I did not work with caffeine, but why do I see this discrepancy between documentation and execution?