【发布时间】:2010-08-07 20:24:16
【问题描述】:
我应该能够覆盖 drawInContext() 并在我的 CALayer 范围之外进行绘制吗?即使我的图层将 maskToBounds 设置为 NO(默认值),我的 drawInContext() 也会使用设置为我图层边界的剪辑调用,但我无法在其外部进行绘制。
我的测试层做这样的事情:
-(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];
}
这只是核心动画层的限制吗? (需要在这个层上面的那个层画吗?)
谢谢。
【问题讨论】: