RubberDucky4444 RubberDucky4444 - 6 months ago 14
Swift Question

Swift animation not resetting when navigating back to that view

I have two views and when you go from view 1 to view 2 through tapping of a button the buttons all animate off screen. If you leave the 2nd page and go back to the first page the elements are all still off screen. Is there a way to have those elements get put back to their original positions in the background after the transition?

This is an example of one of the animations

func loggedInAnimate5(){

UIView.animateWithDuration(3,
delay: 1.2,
options: .CurveEaseIn,
animations: {
self.logo.center.y += self.view.bounds.height
self.logo.alpha = 0.0

}, completion: nil
)

}

Answer

In viewDidDisappear just set the position and alpha value back to where they were initially.

Example:

override func viewDidDisappear(animated: Bool) {
    self.logo.center.y = 100.0
    self.logo.alpha = 1.0
}