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..
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.
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.
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.
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.
Should be set like this in latest Lottie version:
and set animation name 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()
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With