2014-01-08 29 views
3

我已經做了CAShapeLayer與幾點通過設置其筆觸顏色爲紅色。然後我用UIImage的圖案填充顏色。我想旋轉CAShapeLayer以及填充模式使用UIRotationGestureRecognizer如何旋轉一個CAShapeLayer在其中心點

我已經使用CATransform3DRotate,但它不能正常工作。

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

在此先感謝

+0

見我已經使用這個答案[這裏](http://stackoverflow.com/a/8232192/1161906) – bcattle

回答

6

你要撥打:

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

你也開始與身份轉換,其中扔掉你之前所做的任何變換,像定位圖層。你想要做的是:

shapeLayer.transform = CATransform3DRotate(shapeLayer.transform, recognizer.rotation, 0.0, 0.0, 1.0); 
+0

。但整個CAShapeLayer在後臺圍繞UIImageView的中心旋轉。 –

+7

@HiteshBhardwaj在這種情況下,我猜測形狀圖層沒有設置邊界 –