2009-12-01 2 views
1

에 저장하고 CGLayerRef을 읽어 CGLayerRef가에서 생성의어떻게 내가 CGLayerRef "요소"에 대한 질문을 가지고있는 NSMutableArray

내 응용 프로그램에서

, 난 목록을 저장할 비트 맵, 내 DrawRect 좋은 framerate 얻을.

어떻게이 코드에 CGLayerRef를 저장하고 읽을 수 있습니까?

"actualIdp는"그릴 레이어를 식별하기위한 INT는 다음과 같습니다

지금 나의보기에의 drawRect에 대한 코드 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"]]; 

의 저장소에 대한 코드입니다. 여기

-(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 : 당신은 @encode 지침을 왼쪽

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

}; 

답변

2

는 :

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

읽어야합니다

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

당신은 필요에 버퍼의 주소를 넘긴다.. 따라서이 라인은 :

[val getValue:layerToShow]; 

은 다음과 같아야합니다

[val getValue:&layerToShow]; 

내가 그 일을한다고 생각합니다.

+2

이 답변은 좋지만 CGCLayerRef 값을 사용하는 것이 가장 좋습니다.이 줄은 다음과 같습니다 : [layerTable addObject : [[NSValue alloc] initWithBytes : & imageLayer objCType : @encode (CGLayerRef)]]; – Pixman

관련 문제