I saved CGlayerRef and CGcontextRef in NSdata, and when I get them to cover the current one,I find that only the poiners were saved but not the data. For that reason, I can't make these CGlayerRef or CGcontextRef as a copy.(I did this all in drawRect)
Why?some said NSdata could store these things,but NSvalue can not,but ,it dosent work at all, I didnt get the copies of these datas even I used "copy".
Here's my code:
-(void)drawRect:(CGRect)rect{
if (drawCount==3) {
dataLayer1=[NSData dataWithBytes:& _layerView
length:sizeof(CGLayerRef)];
[dataLayer1 retain];
}
if (undodo==YES) {
_layerView=*(CGLayerRef*)[dataLayer1 bytes];
}
currentContext = UIGraphicsGetCurrentContext( ....
Create your CGLayerRef from a bitmap context and make sure to supply a buffer for the bitmap context. Then when you draw into the layer, your bitmap context backing buffer should contain the new data.