【问题标题】:Why is my CGContext clipped to bounds?为什么我的 CGContext 被限制在界限内?
【发布时间】: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];
}

这只是核心动画层的限制吗? (需要在这个层上面的那个层画吗?)

谢谢。

【问题讨论】:

    标签: iphone ipad quartz-2d


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多