Search code examples
iosobjective-ctransformcalayer

How to rotate a CAShapeLayer along with its Pattern?


I have a CAShapeLayer, I am able to rotate it using UIRotationGestureRecognizer. But when rotating, it only rotate its frame not the filled pattern inside it.

        CAShapeLayer *shapeLayer = [finalShapeLayersArray objectAtIndex:indextobeRotated];
        CGPathRef path = createPathRotatedAroundBoundingBoxCenter(shapeLayer.path,recognizer.rotation);
        shapeLayer.path  = path;
        CGPathRelease(path);
        recognizer.rotation = 0;

Bu doing this, it only rotates the boundary of the CAShapeLayer. I have filled a pattern with an image. I just want that pattern should also be rotated.


Solution

  • You need to set a rotation transform on your layer using CALayer's transform property instead (you do not rotate the the shape path then as the whole layer will be rotated).

    See this answer on how to create such a transform. Also see the Core Animation Function Reference for all the functions that can create/modify transformations.