gpt4 book ai didi

objective-c - CAShapeLayer 裁剪图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:11 27 4
gpt4 key购买 nike

我正在尝试使用带有此代码的 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];

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

最佳答案

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

关于objective-c - CAShapeLayer 裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9637270/

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