###前提・実現したいこと
クイズアプリを作成しており、問題が表示されてから回答するまでの時間をx秒に設定。
x秒経過したら、1秒間imageViewでバツ画像を表示そして次の問題へ、という機能を実装中です。
###発生している問題・エラーメッセージ
一回目のfunc timeUp() のUIView.animateWithDurationの引数は呼ばれdelayが適用される。
2回目以降は、func timeUp()は呼ばれているが、delay時間が適用されない。
2回目以降も適用させたいです。
アドバイスよろしくお願いします。
###ソースコード
override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) // アニメーションを付ける. animation() } func animation(){ UIView.animateWithDuration(1.0, animations: { () -> Void in print("call animation") self.startTimer() } ) func startTimer() { time = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: "timer", userInfo: nil, repeats: false) } func timer() { timeUp() print("call timeUp") } func timeUp() { UIView.animateWithDuration(1, delay: 1.0, usingSpringWithDamping: 0.2, initialSpringVelocity: 20, options: [], animations: { self.judgeImageView.image = UIImage(named: "batsu.png")! self.judgeImageView.hidden = false }, //completion: nil) completion: {(finished: Bool) -> Void in // self.nextProblem() }) } func nextProblem(){ judgeImageView.hidden = true //timerを破棄する. time.invalidate() animation() } }
###補足情報(言語/FW/ツール等のバージョンなど)
。。