Add "thinking" spinner
This commit is contained in:
parent
694e71793d
commit
30bffffcf2
|
@ -25,6 +25,7 @@ class HomeViewController: UIViewController {
|
|||
|
||||
lazy var placedChipColumns: [[Chip]] = Array(repeating: [Chip](), count: Board.columns)
|
||||
lazy var strategist = makeStrategist()
|
||||
lazy var thinkingSpinner = makeSpinner()
|
||||
|
||||
var currentGameplayState = GameplayState.inactive {
|
||||
didSet { gameplayStateChanged() }
|
||||
|
@ -36,6 +37,7 @@ class HomeViewController: UIViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
setupUI()
|
||||
resetGame()
|
||||
}
|
||||
|
||||
|
@ -58,6 +60,10 @@ class HomeViewController: UIViewController {
|
|||
|
||||
// MARK: - Helper functions
|
||||
|
||||
func setupUI() {
|
||||
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: thinkingSpinner)
|
||||
}
|
||||
|
||||
func resetGame() {
|
||||
board = Board()
|
||||
strategist.gameModel = board
|
||||
|
@ -170,7 +176,8 @@ class HomeViewController: UIViewController {
|
|||
}
|
||||
|
||||
func toggleBoard(interactionEnabled: Bool) {
|
||||
columnButtons.forEach({ $0.isEnabled = interactionEnabled })
|
||||
columnButtons.forEach { $0.isEnabled = interactionEnabled }
|
||||
interactionEnabled ? thinkingSpinner.stopAnimating() : thinkingSpinner.startAnimating()
|
||||
}
|
||||
|
||||
|
||||
|
@ -206,4 +213,12 @@ class HomeViewController: UIViewController {
|
|||
|
||||
return strategist
|
||||
}
|
||||
|
||||
private func makeSpinner() -> UIActivityIndicatorView {
|
||||
let spinner = UIActivityIndicatorView(style: .gray)
|
||||
|
||||
spinner.hidesWhenStopped = true
|
||||
|
||||
return spinner
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue