iOS App ๋งŒ๋“ค๊ธฐ #1 ๐Ÿฅ

longlivedrgnยท2022๋…„ 2์›” 9์ผ
0

App ๋งŒ๋“ค๊ธฐ

๋ชฉ๋ก ๋ณด๊ธฐ
1/7
post-thumbnail

Lottie๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋„ฃ๊ธฐ


import UIKit
import Lottie

class MainViewController: UIViewController {
    
    let titlelabel : UILabel = {
        let label = UILabel()
        label.textColor = .black
        label.textAlignment = .center
        label.text = "๋ฉ”์ธํ™”๋ฉด"
        label.font = UIFont.boldSystemFont(ofSize: 70)
        return label
    }()
    
    let animationView : AnimationView = {
        let animView = AnimationView(name:"95147-rocket")
        // ์‚ฌ๊ฐํ˜•์„ ๋งŒ๋“ค๊ธฐ
        animView.frame = CGRect(x:0, y:0, width: 400, height: 400)
        
        // contentMode -> ์ด๋ฏธ์ง€๋ฅผ ํ™•๋Œ€ํ• ๊ฑด๊ฐ€ ์ถ•์†Œ๋ฅผ ํ•œ๊ฑด๊ฐ€?
        animView.contentMode = .scaleAspectFill
        return animView
    }()
    
    // ๋ทฐ๊ฐ€ ์ƒ์„ฑ์ด๋˜์—ˆ์„ ๋•Œ๋ฅผ ๋œปํ•œ๋‹ค!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        view.backgroundColor = .black
        view.addSubview(animationView)
        animationView.center = view.center
        
        // ์• ๋‹ˆ๋ฉ”์ด์…˜ ์‹คํ–‰--> closure๋ฅผ ์ด์šฉํ•˜๊ธฐ์— self๋ฅผ ๋‹ค ๋ถ™ํ˜€์ค˜์•ผ๋œ๋‹ค
        animationView.play{(finish) in
            
            print("์• ๋‹ˆ๋ฉ”์ด์…˜์ด ๋๋‚ฌ๋‹ค")
            self.view.backgroundColor = .white
            
            // ์• ๋‹ˆ๋ฉ”์ด์…˜์ด ๋๋‚˜๋ฉด superview์—์„œ animainview๋ฅผ ์ œ๊ฑฐํ•œ๋‹ค.
            self.animationView.removeFromSuperview()
            
            self.view.addSubview(self.titlelabel)
            self.titlelabel.translatesAutoresizingMaskIntoConstraints = false
            self.titlelabel.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
            self.titlelabel.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
        }
        
    }


}

0๊ฐœ์˜ ๋Œ“๊ธ€