CGContextRef 中的坐標係是什麼樣的? (How does the coordinate system in an CGContextRef look like?)


問題描述

CGContextRef 中的坐標係是什麼樣的? (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.

‑‑‑‑‑

參考解法

方法 1:

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.

(by ThanksBrad Larson)

參考文件

  1. How does the coordinate system in an CGContextRef look like? (CC BY‑SA 3.0/4.0)

#cocoa-touch #iphone #uikit #core-graphics






相關問題

防止 UITableView 在自定義子視圖處理觸摸時滾動 (Prevent UITableView from scrolling when custom subview is handling touches)

NSMutableArray removeObjectAtIndex 在第二次執行時崩潰 (NSMutableArray removeObjectAtIndex crashes on second execution)

Apakah NSURLConnections termasuk dalam model atau pengontrol saya? (Do NSURLConnections belong in my model or controller?)

Lợi ích của việc sử dụng NSString tĩnh cho CellIdentifier là gì? (Whats the advantage of using a static NSString for CellIdentifier?)

CGContextRef 中的坐標係是什麼樣的? (How does the coordinate system in an CGContextRef look like?)

無法在不崩潰的情況下設置 ABPeoplePickerNavigationController 的 addressBook 屬性 (Can't set the addressBook property of ABPeoplePickerNavigationController without crashing)

tableViewHeader 拒絕多個子視圖 (tableViewHeader rejecting multiple sub-views)

界面生成器添加了一個標籤欄按鈕,但未顯示 (Interface builder added one tab bar button, but not showing up)

iVar getter / 方法同名? (iVar getter / method with same name?)

如何更改主視圖是基於導航的應用程序! (how to change main view is navigation based app!)

捕捉返回按鈕導航事件 (Catching back button navigation event)

如何將對象轉發到單獨的子視圖? (How can i forward objects to separate subviews?)







留言討論