Guest User

Untitled

a guest
Apr 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // LottieAnimation
  4. //
  5. // Created by 辛忠翰 on 11/04/18.
  6. // Copyright © 2018 辛忠翰. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import Lottie
  11. class Example1ViewController: UIViewController {
  12.  
  13. let animatedButton: UIButton = {
  14. let btn = UIButton(type: .system)
  15. btn.setTitle("Animated!", for: .normal)
  16. btn.addTarget(self, action: #selector(animated), for: .touchUpInside)
  17. btn.backgroundColor = .red
  18. return btn
  19. }()
  20.  
  21. @objc func animated(){
  22. let animationView = LOTAnimationView(name: "bounching_ball")
  23. animationView.center = view.center
  24. animationView.contentMode = .scaleAspectFill
  25. animationView.animationSpeed = 0.8
  26. animationView.loopAnimation = true
  27. view.addSubview(animationView)
  28. animationView.anchor(top: nil, bottom: nil, left: nil, right: nil, topPadding: 0, bottomPadding: 0, leftPadding: 0, rightPadding: 0, width: 200, height: 200)
  29. animatedButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
  30. animatedButton.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
  31. animationView.play()
  32. }
  33.  
  34. func setupView() {
  35. view.addSubview(animatedButton)
  36. animatedButton.anchor(top: nil, bottom: view.bottomAnchor, left: nil, right: nil, topPadding: 0, bottomPadding: 30, leftPadding: 0, rightPadding: 0, width: 100, height: 50)
  37. animatedButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
  38. }
  39.  
  40. override func viewDidLoad() {
  41. super.viewDidLoad()
  42. view.backgroundColor = .white
  43. setupView()
  44. }
  45. }
Add Comment
Please, Sign In to add comment