我正在尝试在基于 UINavigationController 的应用程序上恢复我的动画。
在 viewWillAppear
中,我执行以下操作:
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
self.animateButtons()
}
我还添加了这些:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(addAnimation), name: UIApplicationDidBecomeActiveNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(restorePosition), name: UIApplicationDidEnterBackgroundNotification, object: nil)
这是我的开始/恢复动画:
func addAnimation() {
self.animateButtons()
}
func restorePosition() {
self.restoreToOriginalPosition()
}
所以解释一下:加载 Controller 时,我在 viewDidLoad
中创建按钮 self.makeRoundQButtons
。然后我在 viewWillAppear
中制作动画。
然后,当进入背景时,我恢复它们的原始位置 self.restoreToOriginalPosition()
,并在激活后再次为它们设置动画 func addAnimation() {...}
...
现在这在“事件” View 上工作正常。当我在我的导航树上“向下钻取”时,进入背景并再次激活,并使用“后退”按钮导航到任何“先前” View ,尽管 viewWillAppear
被称为没有动画发生。如果我向前移动然后再返回一切正常......
我做错了什么?
最佳答案
好吧,以防有人想知道...问题是我没有删除 viewDidDissapear
上的 observer
并且所有动画都是一次完成的,因为所有 Controller 都在在导航堆栈中!
关于ios - UIApplicationDidBecomeActiveNotification 后 UINavigationController 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38029321/