Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // LottieAnimation
- //
- // Created by 辛忠翰 on 11/04/18.
- // Copyright © 2018 辛忠翰. All rights reserved.
- //
- import UIKit
- import Lottie
- class Example1ViewController: UIViewController {
- let animatedButton: UIButton = {
- let btn = UIButton(type: .system)
- btn.setTitle("Animated!", for: .normal)
- btn.addTarget(self, action: #selector(animated), for: .touchUpInside)
- btn.backgroundColor = .red
- return btn
- }()
- @objc func animated(){
- let animationView = LOTAnimationView(name: "bounching_ball")
- animationView.center = view.center
- animationView.contentMode = .scaleAspectFill
- animationView.animationSpeed = 0.8
- animationView.loopAnimation = true
- view.addSubview(animationView)
- animationView.anchor(top: nil, bottom: nil, left: nil, right: nil, topPadding: 0, bottomPadding: 0, leftPadding: 0, rightPadding: 0, width: 200, height: 200)
- animatedButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
- animatedButton.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
- animationView.play()
- }
- func setupView() {
- view.addSubview(animatedButton)
- animatedButton.anchor(top: nil, bottom: view.bottomAnchor, left: nil, right: nil, topPadding: 0, bottomPadding: 30, leftPadding: 0, rightPadding: 0, width: 100, height: 50)
- animatedButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- view.backgroundColor = .white
- setupView()
- }
- }
Add Comment
Please, Sign In to add comment