Skip to content

Instantly share code, notes, and snippets.

@Polenoso
Last active May 19, 2021 09:29
Show Gist options
  • Save Polenoso/08da38b8c5e43d5efbed75f5e7fbc9bf to your computer and use it in GitHub Desktop.
Save Polenoso/08da38b8c5e43d5efbed75f5e7fbc9bf to your computer and use it in GitHub Desktop.
Lottie Cache Medium Post
import UIKit
import Lottie
final class AnimationContainerView: UIView {
// MARK: - Initializers
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
setupConstraints()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
assertionFailure("\(#function) not implemented")
}
// MARK: - Properties
private let animationView = AnimationView()
// MARK: - Private
private func setupView() {
animationView.contentMode = .center
addSubview(animationView)
}
private func setupConstraints() {
NSLayoutConstraint.activate(
[animationView.topAnchor.constraint(equalTo: topAnchor),
animationView.bottomAnchor.constraint(equalTo: bottomAnchor),
animationView.trailingAnchor.constraint(equalTo: trailingAnchor),
animationView.leadingAnchor.constraint(equalTo: leadingAnchor)
]
)
}
/// 1
// MARK: Public
func apply(_ viewModel: URL) {
animationView.setAnimation(from: viewModel) { (animationView) in
animationView.loopMode = .loop
animationView.play()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment