How to change the size of the animation json Lottie framework? The initially loaded json looks small, but I need to change the size. Help me please. enter image description here

    1 answer 1

    You simply do not specify the size. To change the size, change the value of the size variable.

    import UIKit import Lottie class ViewController: UIViewController { let animationView = AnimationView() let size: CGFloat = 500 override func viewDidLoad() { super.viewDidLoad() let animation = Animation.named("5438") animationView.animation = animation animationView.play() animationView.loopMode = .loop animationView.frame = CGRect(x: 0, y: 0, width: size, height: size) animationView.contentMode = .scaleAspectFill view.addSubview(animationView) animationView.translatesAutoresizingMaskIntoConstraints = false animationView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true animationView.heightAnchor.constraint(equalToConstant: size).isActive = true animationView.widthAnchor.constraint(equalToConstant: size).isActive = true animationView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true } } 

    Animation

    • Thank! Top pax - Andrey Velin
    • Vanya, and how to make the animation not in the center, but on the top? - Andrey Velin
    • @AndreyVelin Use Auto Layout. I added the answer. - Ivan Kramarchuk
    • My animation size does not change: ( - Andrey Velin
    • @AndreyVelin Show your code. You can copy here: gist.github.com - Ivan Kramarchuk