2

I have a CAShapeLayer that scales to an unknown scale number:

myCAShapeLayer.transform = CATransform3DMakeScale(newScale, newScale, 1)

Then at a certain point, I have to run a CABasicAnimation from current scale back to 1:

let animation1 = CABasicAnimation(keyPath: "transform.scale")
animation1.fromValue = myCAShapeLayer.value(forKeyPath: "transform.scale") as! CGFloat
animation1.toValue = 1.0
animation1.duration = 0.5
myCAShapeLayer.add(animation1, forKey: nil)

when I log myCAShapeLayer.value(forKeyPath: "transform.scale") as! CGFloat after each CATransform3DMakeScale, its always 1.0, though visually the layer is scaled up.

I also tried myCAShapeLayer.presentation()?.value(forKeyPath: "transform.scale") as! CGFloat and its also 1.0

Gizmodo
  • 3,151
  • 7
  • 45
  • 92

1 Answers1

0

If we go to the declaration of CATransform3DMakeScale. We have this information

/* Returns a transform that scales by `(sx, sy, sz)':
 * t' = [sx 0 0 0; 0 sy 0 0; 0 0 sz 0; 0 0 0 1]. */
@available(iOS 2.0, *)
public func CATransform3DMakeScale(_ sx: CGFloat, _ sy: CGFloat, _ sz: CGFloat) -> CATransform3D

So, as we know what indices in matrix are changed for this transform, we can get each as below,

shape.transform = CATransform3DMakeScale(2.09, 4.88, 3.49)
print(shape.transform.m11)
print(shape.transform.m22)
print(shape.transform.m33)

Output:

2.09
4.88
3.49
Kamran
  • 14,987
  • 4
  • 33
  • 51