私の思ったことを綴っていく!

美容もいろいろ気になっている

女の子が走る簡単なiOSアプリを作成した

こんばんは!前回に続いて簡単なアプリを作成してみました。

こんなふうに女の子が走る動画です。

コードはgithubに貼ってあります。 github.com

今回のポイントは絵が指定した時間で変化していくところです。

    @IBAction func run(_ sender: Any) {
        
        runBottun.isEnabled = false
        
        timer1 = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true, block: { (timer) in
            self.countUp = self.countUp + 1
            self.countLabel.text = String(self.countUp)
        })
        
        timer2 = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: { (timer) in
            
            if(self.updateCount > 5){
                self.updateCount = 0
                self.runnerImageView.image = UIImage(named: "dash0.png")
            }else{
                self.runnerImageView.image =
                    self.imageArray[self.updateCount]
            }
            self.updateCount = self.updateCount + 1
        })
    }
    
    
    @IBAction func stop(_ sender: Any) {
        
        runBottun.isEnabled = true
        
        timer1.invalidate()
        timer2.invalidate()


今週末はもっと高度なものを作っていきたいですね。