Swift transform rotate Lottie animatino not working

553 views Asked by At

I have a simple LottieAnimationView and I would like to rotate it by 90 degrees, but .transform has no impact. It is being displayed but the transform is not being applied.

This is how I set it up:

self.view.addSubview(arrowAnimation)
arrowAnimation.translatesAutoresizingMaskIntoConstraints = false
arrowAnimation.heightAnchor.constraint(equalToConstant: screenSize.width/3).isActive = true
arrowAnimation.bottomAnchor.constraint(equalTo: introLabel.topAnchor, constant: -20).isActive = true
arrowAnimation.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
arrowAnimation.contentMode = .scaleAspectFit
arrowAnimation.transform.rotated(by: .pi / 2)
arrowAnimation.animationSpeed = 1.5
arrowAnimation.loopMode = .playOnce

Any idea why the transform is not working here?

1

There are 1 answers

0
Steve B On BEST ANSWER

the below will work:

arrowAnimation.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)

As to the why:

the .transform.rotated(by: .pi/2) returns a transformation, but does not apply it, so you would need to instead do:

arrowAnimation.transform = arrowAnimation.transform.rotated(by: .pi/2)