title: Why I can't stop Progress Bar with Timer?
body: <p>I am doing a <strong>TicTacToe Game</strong>. I want to control every player move with progress bar. If game is end, progress bar must be stopped. If one player moved but the other do not move progress bar must increase or decrease. Here is my codes </p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  
  var activePlayer = 1 // 1 = noughts, 2 = crosses
  var gameState = [0, 0, 0, 0, 0, 0, 0, 0, 0]
  let winningCombinations = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
  var gameActive = true
  var timer = Timer()
  
  @IBOutlet weak var btnPlayAgain: UIButton!
  @IBOutlet weak var progressBar: UIProgressView!
  
  @IBAction func btnPlayAgain(_ sender: AnyObject) {
  </code></pre>
  
  <p>UPDATE</p>
  
  <pre><code>self.view.viewWithTag(1000)?.isHidden = true
  if self.view.viewWithTag(1000)?.isHidden == false {
       self.view.viewWithTag(1000)?.isHidden = true
  }
  </code></pre>
  
  <p>UPDATE</p>
  
  <pre><code>progressBar.progress = 0.5
  
  gameState = [0, 0, 0, 0, 0, 0, 0, 0, 0]
  
  activePlayer = 1
  gameActive = true
  
  
  gameOverLabel.isHidden = true
  gameOverLabel.center = CGPoint(x: gameOverLabel.center.x - 500, y: gameOverLabel.center.y)
  
  btnPlayAgain.isHidden = true
  btnPlayAgain.center = CGPoint(x: btnPlayAgain.center.x - 500, y: btnPlayAgain.center.y)
  
  var buttonToClear : UIButton
  
  for i in 0..&lt;9 {
      buttonToClear = view.viewWithTag(i) as! UIButton
      buttonToClear.setImage(nil, for: .normal)
  
      }
  
  }
  @IBOutlet weak var button: UIButton!
  @IBOutlet weak var gameOverLabel: UILabel!
  
  @IBAction func buttonPressed(_ sender: AnyObject) {
  
      timer = Timer.scheduledTimer(timeInterval: 0.6, target: self, selector: #selector(updateProgress), userInfo: nil, repeats: true)
  
  
  if (gameState[sender.tag] == 0) &amp;&amp; ( gameActive == true) {
  
      gameState[sender.tag] = activePlayer
  
  if activePlayer == 1 {
  sender.setImage(UIImage(named: "nought.png"), for: .normal)
  
      activePlayer = 2
  } else {
      sender.setImage(UIImage(named: "cross.png"), for: .normal)
     activePlayer = 1
  }
  
      for combination in winningCombinations {
          if (gameState[combination[0]] != 0 &amp;&amp;
              gameState[combination[0]] == gameState[combination[1]] &amp;&amp;
              gameState[combination[1]] == gameState[combination[2]]) {
  
              gameActive = false
  
              if (gameState[combination[0]] == 1)
              {
                  gameOverLabel.text = "Noughts has won!"
  
              } else {
                  gameOverLabel.text = "Crosses has won!"
              }
  
             endGame()
          }
      }
      if gameActive == true {
  
      gameActive = false
  
      for buttonState in gameState {
          if buttonState == 0 {
              gameActive = true
          }
      }
      if gameActive == false {
  
          gameOverLabel.text = "It's a draw!"
          endGame()
      }
  }
  }
  
  }
  </code></pre>
  
  <p>How can I control the progress bar is it 1 or 0 ? If 1 or 0 gameLabel.text must be "Crosses or Noughts have won!"        </p>
  
  <pre><code>@objc func updateProgress() {
         if activePlayer == 1 {
             progressBar.progress -= 0.01    
         } else {
             progressBar.progress += 0.01
         }      
  }
  </code></pre>
  
  <p>I want to showing 'winner board' when game is over. I added below codes for showing.It is okay. But when i clicked to playAgain button in the first view is hiding but when the second game is over winner board does not hide</p>
  
  <pre><code>func endGame() {
  
  timer.invalidate()
  gameActive = false
  let rect = UIView(frame: CGRect(x: 0, y: 0, width: 600, height: 500))
  rect.tag = 1000
  rect.backgroundColor = UIColor.white
  
  self.view.addSubview(rect)
  rect.addSubview(gameOverLabel)
  rect.addSubview(btnPlayAgain)
  
  gameOverLabel.isHidden = false
  btnPlayAgain.isHidden = false
  
  progressBar.progress = 0.5
  
  UIView.animate(withDuration: 0.5, animations:{ () -&gt; Void in
  
      self.gameOverLabel.center = CGPoint(x: self.gameOverLabel.center.x + 500, y: self.gameOverLabel.center.y)
  
      self.btnPlayAgain.center = CGPoint(x: self.btnPlayAgain.center.x + 500, y: self.btnPlayAgain.center.y)
  
  })
  
  }
  
  override func viewDidLoad() {
  super.viewDidLoad()
  
  progressBar.progress = 0.5
  
  gameOverLabel.isHidden = true
  gameOverLabel.center = CGPoint(x: gameOverLabel.center.x - 500, y: gameOverLabel.center.y)
  
  btnPlayAgain.isHidden = true
  btnPlayAgain.center = CGPoint(x: btnPlayAgain.center.x - 500, y: btnPlayAgain.center.y)
  }
  </code></pre>