我正在使用 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/