Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using LOTAnimationView with Auto Layout in Storyboard

Is there a way to use LOTAnimationView (Lottie framework) with auto layout? I tried setting the class of a UIView to LOTAnimationView in my storyboard, but getting nil IB outlet..

like image 242
7ball Avatar asked Apr 06 '18 18:04

7ball


People also ask

What are two properties that auto layout constraints control on a Uiview?

Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property. The layoutMargins property lets you get and set the margins as a UIEdgeInsets structure.

How do you add constraints in storyboard IOS?

Open the Align menu with the yellow button selected and check Horizontally in Container, then click Add 1 Constraint. Now, select both buttons at the same time using the Shift key and, in the Align menu, check Leading Edges. Again, actually install the constraint by clicking Add 1 Constraint.

What is the use of auto layout?

Auto Layout defines your user interface using a series of constraints. Constraints typically represent a relationship between two views. Auto Layout then calculates the size and location of each view based on these constraints. This produces layouts that dynamically respond to both internal and external changes.

What is auto layout constraints in Swift?

Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.


Video Answer


2 Answers

Should be set like this in latest Lottie version:

enter image description here

and set animation name here:

enter image description here

and here is example code:

import UIKit
import Lottie

class ViewController: UIViewController {

    @IBOutlet weak var animationView: AnimationView!

    override func viewDidLoad() {
        super.viewDidLoad()

        animationView.play()

    }
}
like image 64
ioio007 Avatar answered Sep 18 '22 14:09

ioio007


enter image description here

Take an outlet of LOTAnimatedControl.

Assign your JSON file to LOTAnimationView

lot.animationView.setAnimation(named: "checked_done_")

Complete example:

import UIKit
import Lottie

class ViewController: UIViewController {
    @IBOutlet weak var lot: LOTAnimatedControl!
    override func viewDidLoad() {
        super.viewDidLoad()
        lot.animationView.setAnimation(named: "youranimationjsonfile")
        lot.animationView.play()
    }
}

Hope this will help you.

like image 21
Ashish Kakkad Avatar answered Sep 20 '22 14:09

Ashish Kakkad