我使用CABasicAnimation
来绘制所有UIBezierPaths
,我使用CAShapeLayer
在一个数组
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = path.color.CGColor;
我的path.color
是来自图像模式的UIColor
。当它转换为CGColor
时,image pattern
是颠倒的。我知道这是因为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;