我正在使用CgLayers在iOS中绘图,现在我想存储这些图层并稍后检索它,所以我想知道有哪些可用选项。我尝试使用NSMutableDictionary,下面是代码,
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGLayerRef testLayer = CGLayerCreateWithContext(UIGraphicsGetCurrentContext(), self.bounds.size, NULL);
CGContextRef context = CGLayerGetContext(testLayer);
CGContextDrawLayerAtPoint(context, CGPointZero, myLayerRef);
// here myLayerRef is my original layer
NSValue *layerCopy = [NSValue valueWithPointer:testLayer];
NSDictionary *lineInfo = [NSDictionary dictionaryWithObjectsAndKeys:layerCopy, @"IMAGE",
nil];
[m_pathArray addObject:lineInfo];
}
-(void) retrieve
{
NSDictionary *lineInfo = [m_pathArray lastObject];
NSValue *val = [lineInfo valueForKey:@"IMAGE"];
CGLayerRef layerRef = (CGLayerRef) [val pointerValue];
CGContextRef context1 = CGLayerGetContext(layerRef);
CGContextDrawLayerAtPoint(context1, CGPointMake(00, 00),layerRef);
[self setNeedsDisplayInRect:self.bounds];
}
此致 兰吉特