Core Graphics coordinate system

霸气de小男生 提交于 2020-02-21 10:22:06

问题


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?


回答1:


"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:.




回答2:


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:


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)];


来源:https://stackoverflow.com/questions/10408786/core-graphics-coordinate-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!