Amir_P Amir_P - 2 months ago 9
Swift Question

application launch animation works only when running from Xcode

I have a view like what i have in

LaunchScreen.storyboard
and I'm scaling that at run with this code in
viewDidLoad
:

UIView.animate(withDuration: 0.4, animations: {
self.aftab_logo.transform = CGAffineTransform(scaleX: 0.6, y: 0.6)
self.aftab_logo.alpha = 0
self.login_content.alpha=1
}, completion: { _ in
self.aftab_logo.removeFromSuperview()
})


When I'm closing app and running again from device this animation doesn't show but when I'm running app from Xcode everything is fine. what is the problem?

Answer

This is because your viewDidload get called before you UI gets layout. so, if you want any animation related you scaling any object then you should use viewDidAppear instead of viewDidload.

Now if you want animation only one time when user start app not when user come to first screen with navigating back then you should set some flag and can store it's value somewhere to manage it.

So, take a try in viewDidAppear instead of viewDidload!

Update :

I have made one demo something like your setup and it works fine in viewDidload also. main issue is your duration is very small for viewdidload to run it.

Once try to change your duration like 2.0 and you will found your animation working perfact!