【发布时间】:2009-12-01 18:22:45
【问题描述】:
我对 CGLayerRef “元素”有疑问(因为它们不是对象!)
在我的应用程序中,我想存储从位图创建的 CGLayerRef 列表,以便在我的 DrawRect 上获得良好的帧速率。
如何在这段代码中存储和读取 CGLayerRef ?
这是存储在 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 的代码:
“actualIdp”是一个int,用于标识要绘制的图层。
-(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 的代码:
-(void)showThisId:(int)idp{
actualIdp = idp;
[self setNeedsDisplay];
};
【问题讨论】:
标签: iphone view quartz-graphics