-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for setting animation after init #347
Conversation
@buba447 Can you give me an example code how to setting animation after init? (Swift version is better) |
@buba447 Now I create only one LOTAnimationView,then by config the LOTCompostion,can I animate A switch to animate B then return to animate A? |
@PizhuLoveCode Can you give sample code? |
@Willyanto my code is a little stupid, if u find better way,please tell me.3q //init
//play1: //swtich to play2
|
@PizhuLoveCode wow thank you bro, it's work. I think it's pretty enough for now. |
Hi is there any example of doing this with ng-lottie in angular? |
This seems like a great feature. Can anyone offer up an example in javascript? Thanks |
Here is a small swift extension (with error handling) that you can drop in your code extension LOTAnimationView {
enum SetAnimationError: LocalizedError {
case PathError(String)
case JsonSerializationError(String)
var errorDescription: String? {
switch self {
case .PathError(let message):
return message
case .JsonSerializationError(let message):
return message
}
}
}
func setAnimation(to jsonFile: String, autoPlay: Bool = true, loop: Bool = false) throws {
if let path = Bundle.main.path(forResource: jsonFile, ofType: "json") {
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
let jsonResult = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
if let jsonResult = jsonResult as? Dictionary<String, AnyObject>{
if let sceneModel = LOTComposition(json: jsonResult, withAssetBundle: nil) {
self.sceneModel = sceneModel
if loop { self.loopAnimation = true }
if autoPlay { self.play() }
}
}
} catch {
throw SetAnimationError.JsonSerializationError("Failed to convert your asset to a json dictionary")
}
} else {
throw SetAnimationError.PathError("Could not find \(jsonFile) in your main bundle")
}
}
} Example Usage: do {
try animView.setAnimation(to: "animName")
} catch let error {
print(error.localizedDescription)
} |
Add support for setting animation after init
Add support for setting animation after init
#344