Search code examples
iosswiftanimationmobileuiinterfaceorientation

IOS animation does not maintain last position


I'm using this method:

UIView.animateWithDuration(1.0, animations: { () -> Void in         
            self.userAndPass.alpha = 1.0
            self.userAndPass.center.y = self.userAndPass.center.y - 72            
            self.vfInicioSesion.center.y = self.vooffInicioSesion.center.y + 72
})

It works great but when I pass from portrait to landscape or visce versa the elements does not maintain their last position (they reset to their initial position).

What can i do in order to get my elements maintain their last position?

willy


Solution

  • You'll need to recalculate the frames and where you want them for a rotated interface and make sure you set their new coordinates when the device is rotated.