【问题标题】:CAShapeLayer cropping imageCAShapeLayer 裁剪图像
【发布时间】:2018-11-29 10:05:03
【问题描述】:

我正在尝试使用带有此代码的 CAShapeLayer 裁剪图像

    CALayer* contentLayer = [CALayer layer];
    CAShapeLayer* mask = [CAShapeLayer layer];

    CGMutablePathRef path = CGPathCreateMutable();

    CGPathMoveToPoint(path, NULL, 10, 10);
    CGPathAddLineToPoint(path, NULL, 10, 80);
    CGPathAddLineToPoint(path, NULL, 80, 80);
    CGPathAddLineToPoint(path, NULL, 80, 10);
    mask.path = path;

    [contentLayer setContents:(id)[[UIImage imageNamed:@"image.png"] CGImage]];
    [contentLayer setMask:mask];          

    [[self layer]addSublayer:contentLayer];

执行此操作后,我只能看到空视图;

【问题讨论】:

    标签: objective-c ios


    【解决方案1】:

    你从不设置contentLayerframe,所以它默认为CGRectZero,这使得它的内容不可见。将框架设置为图像的大小,您应该会看到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 2013-06-05
      • 2022-01-23
      • 2023-04-02
      • 1970-01-01
      • 2015-02-02
      相关资源
      最近更新 更多