George Asda
George Asda

Reputation: 2129

UINavigationController strange behavior after UIApplicationDidBecomeActiveNotification

I am trying to restore my animation on a UINavigationController based app. In viewWillAppear I do the following:

 override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.animateButtons()
    }

I have also added these:

 NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(addAnimation), name: UIApplicationDidBecomeActiveNotification, object: nil)

 NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(restorePosition), name: UIApplicationDidEnterBackgroundNotification, object: nil)

And this is my start/restore animation:

 func addAnimation() {
      self.animateButtons()
    }

  func restorePosition() {
        self.restoreToOriginalPosition()
    }

So to explain: When controller is loaded I create my buttons self.makeRoundQButtons in my viewDidLoad. Then I animate in viewWillAppear.

Then when entering background I restore their original position self.restoreToOriginalPosition()and I animate them again once active func addAnimation() {...}...

Now this works fine on the "active" view. When I "drill" down on my Navigation Tree, enter background and active again, and use the "back" button to navigate to any "previous" view(s) although viewWillAppear is called NO animation happens. If I move forward and then back again everything works fine...

What am I doing wrong?

Upvotes: 1

Views: 47

Answers (1)

George Asda
George Asda

Reputation: 2129

OK in case someone is wondering... The problem was that I wasn't removing the observer on viewDidDissapear and all animation was done at once since all controllers where in the navigation stack!

Upvotes: 1

Related Questions