开发者

How to save and read a CGLayerRef, in a NSmutableArray

i have a question about the CGLayerRef "elements" ( because they are not object !)

In my app, i want to store a list of CGLayerRef created from bitmaps, for obtain a good framerate on my DrawRect.

how can i store and read the CGLayerRef in this code ?

This is the code for store in the NSMutableArray

    CGLayerRef imageLayer;
// create my layer...
// init  m开发者_Python百科y NSMutableArray
if (layerTable == nil) {
    layerTable = [[NSMutableArray alloc] init];
}
// and store my CGCLayer in this array with NSValue
[layerTable addObject:[[NSValue alloc] initWithBytes:imageLayer objCType:"CGLayerRef"]];

Now the code for DrawRect in my view :

"actualIdp" is a int for identify the layer to draw.

-(void)drawInContext:(CGContextRef)context{
// other code...

// here I want to read my CGLayerRef


//test with NSValue, but i don't know NSValue

NSValue *val = [layerTable objectAtIndex:actualIdp];
CGLayerRef layerToShow;
[val getValue:layerToShow]; // maybe an error

CGContextDrawLayerInRect(context, imageRect, layerToShow );

}

Here, the code for change my id :

-(void)showThisId:(int)idp{
actualIdp = idp;
[self setNeedsDisplay];

};


You left out the @encode directive:

[layerTable addObject:[[NSValue alloc] initWithBytes:imageLayer objCType:"CGLayerRef"]];

should read:

[layerTable addObject:[[NSValue alloc] initWithBytes:imageLayer objCType:@encode(CGLayerRef)]];

You need to pass the address of a buffer to [NSValue getValue:]. So this line:

[val getValue:layerToShow];

Should be:

[val getValue:&layerToShow];

I think that should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜