Reputation: 312
According to the documentation for CGRect
In the default Core Graphics coordinate space, the origin is located in the lower-left corner of the rectangle and the rectangle extends towards the upper-right corner. If the context has a flipped-coordinate space—often the case on iOS—the origin is in the upper-left corner and the rectangle extends towards the lower-right corner.
I've always taken it at face value that the coordinate system on iOS starts on the upper-left, but after reading this, it makes sense that it's flipped, and not the default coordinate space. You don't think about points on a Cartesian graph the same way you do on iOS, where adding to the Y value shifts down, not up.
The documentation says it's 'often the case', so when is it not the case on iOS? And on what platforms is the coordinate space the Core Graphics default?
Upvotes: 1
Views: 199
Reputation: 318804
In iOS and UIKit, the origin is in the upper-left and positive y values go toward the bottom of the screen.
But for the lower level Quartz APIs, the origin is in the lower-left with y values going up toward the top of the screen.
This is covered in the Quartz 2D Programming Guide under the section titled Drawing to a View Graphics Context in iOS.
The default coordinate system used throughout UIKit is different from the coordinate system used by Quartz. In UIKit, the origin is in the upper-left corner, with the positive-y value pointing downward. The UIView object modifies the CTM of the Quartz graphics context to match the UIKit conventions by translating the origin to the upper left corner of the view and inverting the y-axis by multiplying it by -1. For more information on modified-coordinate systems and the implications in your own drawing code, see Quartz 2D Coordinate Systems.
So the "often the case" is when using UIKit. It's not the case when using lower level Quartz APIs.
Upvotes: 3