How to rotate a CAShapeLayer at its center point

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


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);
链接地址: http://www.djcxy.com/p/74252.html

上一篇: 没有动画改变CAShapeLayer

下一篇: 如何旋转CAShapeLayer的中心点