应用程序从后台返回 - 更改bar的frame.origin

时间:2015-02-28 12:42:38

标签: ios xcode background

我有一个导航栏,当桌面向上滚动时会改变它的位置。它工作得很好但是当我的应用程序进入后台并且下一次返回时 - 导航栏位于其基本位置,而不是输入背景之前的位置。我使用通知中心来改变它的位置

    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
}

在选择器中我改变了原点,但它仍然在基本的地方,我需要把它放到旧的地方!我该怎么做?

0 个答案:

没有答案