Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 缩放并将calayer居中到superview_Objective C_Autolayout_Calayer - Fatal编程技术网

Objective c 缩放并将calayer居中到superview

Objective c 缩放并将calayer居中到superview,objective-c,autolayout,calayer,Objective C,Autolayout,Calayer,缩放图层时,结果始终将原点设置为CGPoint(0,0)。什么是确保缩放后图层仍位于其超级图层中心的最佳方法 [CATransaction begin]; [CATransaction setAnimationDuration: 0]; [CATransaction setDisableActions: TRUE]; self.maskLayer.transform = CATransform3DScale(CATransform3DIdentity, .8, .8,1); self.mask

缩放图层时,结果始终将原点设置为CGPoint(0,0)。什么是确保缩放后图层仍位于其超级图层中心的最佳方法

[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];

您需要将层的锚点设置为其中心:

self.maskLayer.anchorPoint = CGPointMake(0.5, 0.5);
然后将其位置设置为其超层的中心

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

我试过了,但它不能移动图层。在提交内部和外部。我编辑了我的问题以包括它,所以我检查了锚定点,它仍然默认为0.5,0.5