RubberDucky4444 RubberDucky4444 - 8 months ago 24
Swift Question

Swift how to animate up the screen while staying centered, but also shrink in size

I want to do a simple animation where the logo moves from point A on the screen at size 1 to point B on the screen at size 2

I found

self.logoOutlet.frame = CGRect(x: x, y: y, width: 115, height: 115)

how do i get it so the x is centered no matter what size the phone is?


You either have to do math, to calculate the value of x based on the bounds of the superview of logoOutlet or use AutoLayout and just use a center X constraint (which is probably the better choice).

You can read about the specifics in the documentation: Auto Layout Guide, or use one of the many tutorials on Auto Layout you can find via Google search.