Last active
May 19, 2021 09:29
-
-
Save Polenoso/08da38b8c5e43d5efbed75f5e7fbc9bf to your computer and use it in GitHub Desktop.
Lottie Cache Medium Post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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