10
votes

When overriding drawRect I've found that the coordinates there use 0,0 as the upper left.

But the Apple UIView Programming Guide says this:

Some iOS technologies define default coordinate systems whose origin point and orientation differ from those used by UIKit. For example, Core Graphics and OpenGL ES use a coordinate system whose origin lies in the lower-left corner of the view or window and whose y-axis points upward relative to the screen.

I'm confused; are they talking about something different than Quartz when they refer to Core Graphics here?

3

3 Answers

9
votes

"Core Graphics" in this documentation means "Quartz", yes. It's just an oversimplification.

When you create a CGContext yourself, its coordinate system has the origin in the bottom-left. When UIKit creates the CGContext for drawing into a view, it helpfully flips the coordinate system before calling -drawRect:.

3
votes

Core Graphics and Quartz on iOS are, as far as coordinates go, the same thing. The iOS Technologies Guide says so:

Core Graphics (also known as Quartz)...

The Core Graphics framework (CoreGraphics.framework) contains the interfaces for the Quartz 2D drawing API. Quartz is the same advanced, vector-based drawing engine that is used in Mac OS X.

The distinction is that, technically, Quartz is the technology or the mechanism, and "Core Graphics" is the name of the framework. (On Mac OS, of course, there's actually a "Quartz" framework, which is just an umbrella.)

3
votes

For the benefit of others finding this thread:

There is a full explanation of the coordinate systems here: Coordinate Systems in Cocoa

It is not exactly helpful that they differ. There are methods to convert between coordinate systems at the various levels of view in your App! For example this finds the coordinates of the point that it at (20,20) in the visible screen on a zoomed image. The result is relative to the origin of the zoomed image which may now be way off in space.

croppingFrame.origin = [self convertPoint:CGPointMake(20.0, 20.0) fromCoordinateSpace:(self.window.screen.fixedCoordinateSpace)];