Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

iphone - How does the coordinate system in an CGContextRef look like?

I assume that the origin is on the bottom left, and the y-axis expands up, starting from 0. The x-axis expands to the right, starting from 0.

I just ask because I get very weird results from my drawing code... want to make sure that I didn't get this part wrong.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It depends on where this context is being used. The standard Core Graphics drawing context used on the Mac for view, layer, and image drawing has (0,0) for its bottom left coordinate.

The standard coordinate system on the iPhone is inverted, with the upper left coordinate for a UIView being (0,0). Its backing layer also has those flipped coordinates, so drawing into a context for the view or its layer starts at (0,0) for the upper left. UIImage contexts are also flipped in this manner, but PDF contexts are not.

All of this is documented in various locations within Apple's iPhone programming guides, but it can be a bit confusing to sort out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...