Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Swift Animation - Move image to the new position

I am trying to implement this cool feature where the logo after the app loads moves up slightly and the login view appears. The problem is that when I use this code:

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        UIView.animateWithDuration(2, animations: {
            var newCenter = self.logoImage.center
            newCenter.y -= 100
            self.logoImage.center = newCenter
            }, completion: { finished in
                println("Basket doors opened!")
        })
    }

The logo is moved to the origin place from the place I want it to move to. So in this example logo appears already with (y-100) and then moves to the origin X,Y.

like image 946
ekussberg Avatar asked Jan 09 '23 18:01

ekussberg


1 Answers

Since the view isn't actually laid out / on the screen in viewDidLoad() you shouldn't be trying to animate anything there. Instead, you should wait until the view is completely presented, which happens in viewDidAppear(animated: Bool). Also, I would recommend calculating the newCenter var outside of the animation call, then simply setting self.logoImage.center = newCenter within the animation call.

like image 170
sfeuerstein Avatar answered Jan 16 '23 21:01

sfeuerstein