Last active
March 8, 2020 00:22
-
-
Save asilturk/9cab83ae7fcdff6445a385e748bbcf54 to your computer and use it in GitHub Desktop.
Lottie animation
This file contains hidden or 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
// | |
// ViewController.swift | |
// demoLottie | |
// | |
// Created by Burak Furkan Asilturk on 8.03.2020. | |
// Copyright © 2020 Burak Furkan Asilturk. All rights reserved. | |
// | |
import UIKit | |
import Lottie | |
class ViewController: UIViewController { | |
let animationView = AnimationView() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setAnimationView() | |
} | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
playAnimation() | |
} | |
} | |
// MARK: - Animations | |
extension ViewController { | |
func playAnimation() { | |
animationView.play(fromProgress: 0, | |
toProgress: 1, | |
loopMode: LottieLoopMode.loop, | |
completion: { (finished) in | |
if finished { | |
print("Animation Complete") | |
} else { | |
print("Animation cancelled") | |
} | |
}) | |
} | |
func setAnimationView() { | |
let animation = Animation.named("bookanimation")//, subdirectory: "qwe") | |
animationView.animation = animation | |
animationView.contentMode = .scaleAspectFit | |
view.addSubview(animationView) | |
view.translatesAutoresizingMaskIntoConstraints = false | |
animationView.backgroundBehavior = .pauseAndRestore | |
animationView.frame = self.view.frame | |
animationView.contentMode = .scaleAspectFit | |
// | |
// animationView.translatesAutoresizingMaskIntoConstraints = false | |
// animationView.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor).isActive = true | |
// animationView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true | |
// | |
// animationView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true | |
// animationView.setContentCompressionResistancePriority(.fittingSizeLevel, for: .horizontal) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment