使用以下代码,我一直试图让我的CALayer围绕其中心缩放 - 但它是以左上角(0,0)为中心缩放的。我看到了这个问题:CALayer中的锚点并尝试设置了anchorPoint - 但在我设置之前它已经是[.5,.5]了,并且设置没有任何区别。还尝试设置
设置如下:我在
我已经调整了几个小时 - 这一定是什么简单的东西,但我还没有弄清楚。
contentsGravity
。设置如下:我在
self.view.layer
中添加了一个CAShapeLayer
,在其中进行一些绘图,然后添加CABasicAnimation。动画运行良好 - 但它向顶部/左侧缩放 - 而不是视图的中心。我已经调整了几个小时 - 这一定是什么简单的东西,但我还没有弄清楚。
shapeLayer.anchorPoint = CGPointMake(.5,.5);
shapeLayer.contentsGravity = @"center";
printf("anchorPoint %f %f\n", shapeLayer.anchorPoint.x, shapeLayer.anchorPoint.y);
CABasicAnimation *animation =
[CABasicAnimation animationWithKeyPath:@"transform.scale"];
animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
[animation setDuration:1.0];
animation.fillMode=kCAFillModeForwards;
animation.removedOnCompletion=NO;
[shapeLayer addAnimation:animation forKey:@"zoom"];