2011-11-22 26 views
0

我使用[NSGraphicsContext currentContext]獲取上下文,我如何獲得當前應用的NSAffineTransform如何從NSGraphicsContext獲取NSAffineTransformation

我需要這個實現我自己的轉型堆在那裏我可以執行就像在OpenGL glPushMatrix()glPopMatrix()pushpop行動。

[NSGraphicsContext saveGraphicsState]不是爲我做的,因爲它不可堆疊,還是它?

回答

2

它是。在將更改應用到上下文並恢復之前保存圖形狀態。每個saveGraphicsState必須與相應的restoreGraphicsState呼叫配對。

// Initial state 

[NSGraphicsContext saveGraphicsState]; 

[transform1 concat]; 
// State 1. 
//Draw with transform1 concatenated with the current transform of the context 

[NSGraphicsContext saveGraphicsState]; 

[transform2 set]; 
// State 2 
// draw with transform2 that replaces the transform of the context 

[NSGraphicsContext restoreGraphicsState]; 

// now we have State 1 again 

[NSGraphicsContext restoreGraphicsState]; 

// We came back to the initial state 
+0

非常感謝您的快速響應!我之前嘗試過,但由於某種原因無法使用。它現在並且我很高興。 – weezor

+0

不客氣。 – Davyd