[英]CAShapeLayer strokeColor from image pattern UIColor to CGColor upside down
I'm using CABasicAnimation
to draw all UIBezierPaths
i have in an Array using CAShapeLayer
我使用
CABasicAnimation
绘制所有UIBezierPaths
我在使用数组CAShapeLayer
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = path.color.CGColor;
My path.color
is a UIColor
from image pattern. 我的
path.color
是图像图案的UIColor
。 When it is converted to CGColor
the image pattern
is upside down. 将其转换为
CGColor
, image pattern
会颠倒。 I know that is because iOS and core graphics use different starting points for drawing. 我知道这是因为iOS和核心图形使用不同的绘图起点。
I have tried 我努力了
shapeLayer.transform = CATransform3DMakeRotation(M_PI, 0.0, 0.0, 1.0);
and 和
shapeLayer.geometryFlipped = YES;
But none of them worked. 但是他们都不起作用。
How do I flip the strokeColor
image pattern 180 degree to match with the origin UIColor
? 如何将
strokeColor
图像图案翻转180度以与原点UIColor
匹配?
As you have correctly suspected, the coordinate system differs. 正如您已经正确怀疑的那样,坐标系有所不同。 In this case, the origin is at the bottom left at
(0, 0)
. 在这种情况下,原点位于
(0, 0)
的左下角。
So what you could do to compensate that is to either flip the image yourself using an image editor or do it in code like so: 因此,您可以采取的补偿措施是使用图像编辑器自己翻转图像或使用以下代码进行操作:
UIImage *flippedPatternImage = [UIImage imageWithCGImage:patternImage.CGImage scale:1.0f orientation:UIImageOrientationLeftMirrored];
UIColor *colorWithImagePattern = [UIColor colorWithPatternImage:flippedPatternImage];
And finally assign it to the strokeColor
: 最后将其分配给
strokeColor
:
shapeLayer.strokeColor = path.color.CGColor;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.