LoginSignup
0
0

More than 1 year has passed since last update.

Lottie アニメーションの復習

Posted at

今回の内容

6768F835-3B35-4FA7-B1C1-B12A1593089B_1_201_a.jpeg

コードと簡単解説


import Lottie 

           ~~~~~~~~~~省略~~~~~~~~~~

    override func viewDidLoad() {
        super.viewDidLoad()

        let animationStartButton = {() -> UIButton in

            let button = UIButton(frame: CGRect(x: view.frame.maxX / 4, y: view.frame.maxX / 3, width: view.frame.width / 2, height: view.frame.height / 20))
            button.setTitle("Start", for: .normal)
            button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20)
            button.titleLabel?.textColor = .white
            button.backgroundColor = .systemGreen
            button.layer.cornerRadius = 15.0
            button.layer.shadowOffset = CGSize(width: 5, height: 5)
            button.layer.shadowRadius = 5.0
            button.layer.shadowOpacity = 0.8
            button.addTarget(self, action: #selector(showLottie), for: .touchDown)
            return button
        }()
        view.addSubview(animationStartButton)       
    }

    @objc func showLottie(sender:UIButton){

        let lottieAnimationView = AnimationView() 
        lottieAnimationView.frame = CGRect(x: view.frame.maxX / 4, y: view.frame.maxY / 4, width: view.frame.width / 2, height: view.frame.width / 2)
        lottieAnimationView.backgroundColor = .clear
        lottieAnimationView.animation = Animation.named("ダウンロードしてきたデータの名前") //表示するアニメーションを設定
        lottieAnimationView.contentMode = .scaleToFill
        lottieAnimationView.loopMode = .loop //繰り返しアニメーションをします 
        lottieAnimationView.play() //アニメーションを開始します
        view.addSubview(lottieAnimationView)

        DispatchQueue.main.asyncAfter(deadline: .now() + 5) {

            lottieAnimationView.removeFromSuperview() //画面から消します
            lottieAnimationView.stop() //アニメーションを停止します 
        }

           ~~~~~~~~~~省略~~~~~~~~~~

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0