我有一个导航栏,当桌面向上滚动时会改变它的位置。它工作得很好但是当我的应用程序进入后台并且下一次返回时 - 导航栏位于其基本位置,而不是输入背景之前的位置。我使用通知中心来改变它的位置
var navBarOldFrame : CGPoint!
override func viewDidLoad() {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "becameActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "enterForeground", name: UIApplicationWillEnterForegroundNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "inactiveState", name: UIApplicationWillResignActiveNotification, object: nil)
super.viewDidLoad()
}
func inactiveState(){
print("inactive:")
println(navBar.frame.origin.y)
navBarOldFrame = navBar.frame.origin
}
func enterForeground(){
print("active:")
println(navBar.frame.origin.y)
navBar.frame.origin = navBarOldFrame
}
func becameActive(){
print("active:")
println(navBar.frame.origin.y)
navBar.frame.origin = navBarOldFrame
}
在选择器中我改变了原点,但它仍然在基本的地方,我需要把它放到旧的地方!我该怎么做?