Reputation: 14527
I have a CAShapeLayer
which contains a CGMutablePath
that has a stroke drawn around it. In my app, I transform this CAShapeLayer
to increase / decrease it's size at certain times. I'm noticing when I transform the CAShapeLayer
, the stroke
gets transformed as well. Ideally I'd like to keep the lineWidth
of the stroke
at 3 at all times even when the CAShapeLayers
transformed.
I tried shutting off the stroke before I transformed then readding it afterwards but it didn't work:
subLayerShapeLayer.lineWidth = 0;
subLayerShapeLayer.strokeColor = nil;
self.layer.sublayerTransform = CATransform3DScale(self.layer.sublayerTransform, graphicSize.width / self.graphic.size.width, graphicSize.height / self.graphic.size.height, 1);
shapeLayer.strokeColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor;;
shapeLayer.lineWidth = 3;
Does anyone know how I might be able to accomplish this task? Seems as though it should be able to redraw the stroke after transforming somehow.
Upvotes: 3
Views: 1117
Reputation: 27597
Transform the CGPath itself and not its drawn representation (the CAShapeLayer).
Have a close look at CGPathCreateMutableCopyByTransformingPath - CGPath Reference
CGPathCreateMutableCopyByTransformingPath
Creates a mutable copy of a graphics path transformed by a transformation matrix.
CGMutablePathRef CGPathCreateMutableCopyByTransformingPath(
CGPathRef path,
const CGAffineTransform *transform
);
Parameters
path
The path to copy.
transform
A pointer to an affine transformation matrix, or NULL if no transformation is needed. If specified, Quartz applies the transformation to all elements of the new path.
Return Value
A new, mutable copy of the specified path transformed by the transform parameter. You are responsible for releasing this object.
Availability Available in iOS 5.0 and later. Declared In CGPath.h
Upvotes: 3