2010-08-07 3 views
3

drawInContext()를 재정의하고 내 CALayer 경계 외부로 그릴 수 있어야합니까? 내 레이어의 maskToBounds가 NO (기본값)로 설정되어 있어도 내 레이어의 경계로 설정된 클립으로 drawInContext()가 호출되고 그 바깥 쪽을 그릴 수 없습니다.왜 내 CGContext가 경계로 클리핑됩니까?

내 시험 층은 다음과 같이 수행합니다

-(void)drawInContext:(CGContextRef)context 
{ 
    [super drawInContext:context];  
    NSLog(@"mask to bounds=%d", self.masksToBounds); // NO 
    CGRect clip = CGContextGetClipBoundingBox(context); 
    NSLog(@"clip=%f,%f,%f,%f", clip.origin.x, clip.origin.y, clip.size.width, clip.size.height); // reports the bounds 

    CGContextSetStrokeColorWithColor(context, [[UIColor whiteColor] CGColor]); 
    CGContextBeginPath(context); 
    CGContextSetLineWidth(context, 5.0); 
    CGContextMoveToPoint(context, 0, 0); 
    CGContextAddLineToPoint(context, 500, 0.0); // wider than my layer... 
    CGContextStrokePath(context); 
} 

을 여기에 내가 그것을 설정하는 방법은 다음과 같습니다

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    CALayer *layer = [[MyLayer alloc] init]; 
    layer.needsDisplayOnBoundsChange=YES; 
    layer.frame = CGRectMake(50, 50, 200, 200); 
    [self.view.layer addSublayer:layer]; 
} 

코어 애니메이션 레이어의 단지 제한이 있습니까? (이 레이어 위에 레이어를 그려야합니까?)

감사합니다.

답변

4

레이어의 내용이 경계를 오버플로하는 방법은 없습니다. 그러나 범위를 벗어난 프레임을 지정하고 masksToBounds 속성을 NO (기본값)으로 설정하여 오버플로하는 하위 레이어를 추가 할 수 있습니다.