2012-07-31 59 views
4

當我縮放一個圖層時,結果總是在CGPoint(0,0)處設置原點。確保規模後最好的方法是什麼,圖層仍然位於超級圖層的中心?比例和中心calayer超級查看

[CATransaction begin]; 
[CATransaction setAnimationDuration: 0]; 
[CATransaction setDisableActions: TRUE]; 

self.maskLayer.transform = CATransform3DScale(CATransform3DIdentity, .8, .8,1); 
self.maskLayer.position = CGPointMake(kScreenWidth/2,kScreenHeight/2); 

[CATransaction commit]; 

回答

6

您需要設置圖層的anchorPoint是它的中心:

self.maskLayer.anchorPoint = CGPointMake(0.5, 0.5); 

,然後設置其位置的其superLayer

self.maskLayer.position = (CGPoint){CGRectGetMidX(superLayer.bounds), CGRectGetMidY(superLayer.bounds)}; 
+0

中心我試過了,但它不不移動圖層。在提交內部和外部。我編輯我的問題,包括它 – prostock 2012-07-31 23:29:52

+1

也,我檢查了錨點,它仍然默認爲0.5,0.5 – prostock 2012-07-31 23:33:00