问题描述
我对CGLayerRef elements有疑问(因为它们不是对象!)
i have a question about the CGLayerRef "elements" ( because they are not object !)
在我的应用程序中,我想存储从中创建的CGLayerRef列表位图,以便在DrawRect上获得良好的帧率。
In my app, i want to store a list of CGLayerRef created from bitmaps, for obtain a good framerate on my DrawRect.
我如何存储和读取此代码中的CGLayerRef?
how can i store and read the CGLayerRef in this code ?
这是存储在NSMutableArray中的代码
This is the code for store in the NSMutableArray
CGLayerRef imageLayer;
// create my layer...
// init my 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"]];
现在在我看来是DrawRect的代码:
Now the code for DrawRect in my view :
actualIdp是用于标识要绘制的图层的整数。
"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 );
}
在这里,更改我的ID的代码:
Here, the code for change my id :
-(void)showThisId:(int)idp{
actualIdp = idp;
[self setNeedsDisplay];
};
推荐答案
您忽略了 @编码
指令:
[layerTable addObject:[[NSValue alloc] initWithBytes:imageLayer objCType:"CGLayerRef"]];
应读为:
[layerTable addObject:[[NSValue alloc] initWithBytes:imageLayer objCType:@encode(CGLayerRef)]];
您需要将缓冲区的地址传递给 [NSValue getValue:]
。所以这行:
You need to pass the address of a buffer to [NSValue getValue:]
. So this line:
[val getValue:layerToShow];
应为:
[val getValue:&layerToShow];
我认为应该可以。
这篇关于如何在NSmutableArray中保存和读取CGLayerRef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!