我有一個手指繪畫視圖,我正在實現撤消/重做。所有繪圖都發生在名爲lineLayer的CGLayer上。iPhone - 將字典中的值從字典推送到CGlayer
只要用戶觸摸屏幕,但在對屏幕進行任何修改之前,我需要快速獲取視圖內容並創建撤消級別。
顯然將視圖保存到磁盤不是一個選項,因爲它需要很長時間。我想象中的解決方案是將CGLayer複製到字典中,使用這樣的事情:
// I copy the layer as a NSValue
NSValue *layerCopy = [NSValue valueWithBytes:&myLayer objCType:@encode(CGLayerRef)];
我把它保存在一個字典
NSString *aKey = [NSString stringWithFormat:@"%d", [number intValue]];
[self.dictUNDO setObject:layerCopy forKey:aKey];
後來我用取回
NSString *myKey = [NSString stringWithFormat:@"%d", [number intValue]];
NSValue *myCopy = [self.dictUNDO objectForKey:myKey];
[myCopy getValue:&lineLayer];
//lineLayer is the CGLayer where the drawing happens
問題在於lineLayer完全沒有被該讀取操作改變。 它繼續具有與以前相同的內容。
我錯過了什麼嗎?
謝謝。
HI橡皮鴨,你成功的方法嗎? – Ranjit 2012-07-12 10:56:55