3

I have made a CAShapeLayer with few points by setting its stroke color to red . Then i have filled the color with a pattern of an UIImage. I want to rotate that CAShapeLayer along with its filled pattern using UIRotationGestureRecognizer.

I have used CATransform3DRotate but it is not working properly.

CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DRotate(transform, recognizer.rotation, 0.0, 0.0, 1.0);
shapeLayer.transform = transform;

Thanks in advance

BytesGuy
  • 4,097
  • 6
  • 36
  • 55

1 Answers1

9

You'll want to call:

shapeLayer.anchorPoint = (CGPoint){0.5, 0.5};

You're also starting with the identity transform, which throws away any transformations you've done before, like positioning the layer. What you want to do is:

shapeLayer.transform = CATransform3DRotate(shapeLayer.transform, recognizer.rotation, 0.0, 0.0, 1.0);
Wil Shipley
  • 9,343
  • 35
  • 59