0

I create View and defined size to view And created Outlet to it picture one

After code my animate ignores size of View and located by itself. And I need locate animation inside View, but I don't have more ideas.

picture two

My code for animation:

func lottieAnimation() {
            let animationView = AnimationView(name: "japan")
            animationView.center = self.view.center
            animationView.contentMode = .scaleAspectFit
            animationView.frame = self.view.bounds
            view.addSubview(animationView)
            animationView.play()
            animationView.loopMode = .loop
        }

Can you help me?

1 Answers1

0

You programmatically create new AnimationView and bring it to 'view' in lottieAnimation() function. That's why your animation is centered.

First of all, you should work with previously created IBOutlet.

lottieAnimation() should only configure existing animation because you already have constraints for the AnimationView (as I can see on picture one).

//'animationView' should be changed to IBOutlet name for animation
func lottieAnimation() {
    animationView.animation = AnimationView(name: "japan")
    animationView.loopMode = .loop
    animationView.play()
}

And don't forget that animation (that you upload to project in .json files) might have it's own width and height parameters that can be changed inside the animation code (in .json file).

Raman Shyniauski
  • 392
  • 2
  • 13