この質問で、UIViewをflipしながらUIView上のラベルにカウントアップした整数を表示する方法を教えて頂きました。この回答を参考に、カウントダウンのボタンも設置し、カウントダウンの機能を実装しようとしたのですが、うまく動作しません。以下がコードですが、どの様に修正すれば良いでしょうか。
import UIKit class ViewController: UIViewController { var count = 0 @IBOutlet weak var countView: UIView! @IBOutlet weak var countLabel: UILabel! @IBAction func countUp(_ sender: Any) { sender.isEnabled = false // ボタンを使用不能にし、連続クリックを防止 UIView.transition( with: self.countView, // 緑のビューをアニメーション duration: 1.0, // 1.0秒でアニメーション options: UIViewAnimationOptions.transitionFlipFromLeft, // 左辺が持ち上がり垂直回転軸でフリップ animations: {() -> Void in self.countUp()}) // 裏返ったらカウントを増加 completion: {(_) -> Void in (sender as AnyObject).isEnabled = true}) // アニメーション終了後にボタンを使用可能にする } @IBAction func countDown(_ sender: Any) { sender.isEnabled = false // ボタンを使用不能にし、連続クリックを防止 UIView.transition( with: self.countView, // 緑のビューをアニメーション duration: 1.0, // 1.0秒でアニメーション options: UIViewAnimationOptions.transitionFlipFromLeft, // 左辺が持ち上がり垂直回転軸でフリップ animations: {() -> Void in self.countDown()}) // 裏返ったらカウントを増加 completion: {(_) -> Void in (sender as AnyObject).isEnabled = true}) // アニメーション終了後にボタンを使用可能にする } private func countUp(){ count += 1 countLabel.text = String("Count=\(self.count)") print(self.count) } private func countDown(){ count -= 1 countLabel.text = String("Count=\(self.count)") print(self.count) } override func viewDidLoad() { super.viewDidLoad() self.countUp() self.countDown() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/13 22:56
2017/06/14 00:08
2017/06/14 00:46
2017/06/14 02:03