I am trying to implement a Lottie AnimationView
inside my app but I am having trouble resizing the view.
This is how I setup/constrain
the AnimationView
:
@objc func showAnimationTapped(){
let logoAnimation = AnimationView(name: "StrokeAnimation")
logoAnimation.contentMode = .scaleAspectFit
self.view.addSubview(logoAnimation)
logoAnimation.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
logoAnimation.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
logoAnimation.heightAnchor.constraint(equalToConstant: 200).isActive = true
logoAnimation.widthAnchor.constraint(equalToConstant: 200).isActive = true
logoAnimation.play()
}
The problem is that XCode is breaking all the constraints and the AnimationView
is wrongly placed/scaled. I also checked the View Hirarchy
and the AnimationView
is actually covering the whole screen... Also tried it with CGRect
but that doesn't change anything.
How can I resize/constrain the animation in Swift 5?
I couldn't find anything on this topic.. I am grateful for every help!
Maybe something is wrong with my AE-file, because when I previewed it on Lottiefiles.com the "Stroke" is not the same animation as in me AE-file.
However I also tested it with a file directly from Lottie and that caused the same problem...
So maybe there is a Swift/Lottie/AfterEffects expert who can help me out here :)
Here is my AE-File + JSON-file for a better understanding. If there is anything unclear, just let me know.