gpt4 book ai didi

ios - CAShapeLayer strokeColor 从图像模式 UIColor 到 CGColor 颠倒

转载 作者:行者123 更新时间:2023-11-29 12:21:15 25 4
gpt4 key购买 nike

我正在使用 CABasicAnimation 绘制我在数组中使用 CAShapeLayer 的所有 UIBezierPaths

CAShapeLayer *shapeLayer = [CAShapeLayer layer];    
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = path.color.CGColor;

我的 path.color 是来自图像模式的 UIColor。当它转换为 CGColor 时,图像模式 是颠倒的。我知道这是因为 iOS 和核心图形使用不同的绘图起点。

我试过了

shapeLayer.transform = CATransform3DMakeRotation(M_PI, 0.0, 0.0, 1.0);

shapeLayer.geometryFlipped = YES;

但它们都不起作用。

如何将 strokeColor 图像图案翻转 180 度以匹配原点 UIColor

最佳答案

正如您猜想的那样,坐标系不同。在这种情况下,原点位于左下角 (0, 0)

因此,您可以通过使用图像编辑器自己翻转图像或使用如下代码来弥补这一点:

UIImage *flippedPatternImage = [UIImage imageWithCGImage:patternImage.CGImage scale:1.0f orientation:UIImageOrientationLeftMirrored];

UIColor *colorWithImagePattern = [UIColor colorWithPatternImage:flippedPatternImage];

最后将它分配给 strokeColor:

shapeLayer.strokeColor = path.color.CGColor;

关于ios - CAShapeLayer strokeColor 从图像模式 UIColor 到 CGColor 颠倒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30563031/

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