gpt4 book ai didi

iphone - 为什么我的 CGContext 被剪裁到边界?

转载 作者:行者123 更新时间:2023-12-03 19:42:37 30 4
gpt4 key购买 nike

我是否应该能够重写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];
}

这只是核心动画层的限制吗? (是否需要在该图层之上的图层中进行绘制?)

谢谢。

最佳答案

图层的内容不可能溢出其边界;但是,您可以通过指定延伸到边界之外的框架并将 masksToBounds 属性设置为 NO(默认值)来添加溢出的子图层。

关于iphone - 为什么我的 CGContext 被剪裁到边界?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3431914/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com