Kasper Hansen Kasper Hansen - 1 year ago 112
iOS Question

Xcode with swift: Is it possible to show a view controller upon another without resetting the first?

I'm creating a simple game with a pause button. I want to show another view controller with the pause screen without resetting the game view controller when i return. Every thing i have tried, has resulted in the game view controller being reset, when i press the resume button and return to the game.
Does anybody know how i can do this without resetting the game?
It's a sprite kit and swift iOS app in xcode.

Answer Source

You can show a pop-up based view. You can create .xib and design your pause view as you wish. Then you can resume the game without resetting anything.

Sample code:

  // Set Pause Page
  var pauseView  = PauseView.loadFromNib() // need an extension

  @IBAction func Pause(sender: UIButton) {
    pauseView.btnResume.addTarget(self, action: #selector(resume(_:)), forControlEvents: .TouchUpInside)
    // set place on view

  func resume(sender:UIButton) {

I created a demo for you:

Full demo available on Github: Get Source Code

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download