[英]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
: 我有一个类似LaunchScreen.storyboard
的视图,并且正在使用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. 当我关闭应用程序并从设备再次运行时,此动画不会显示,但是当我从Xcode运行应用程序时,一切都很好。 what is the problem? 问题是什么?
This is because your viewDidload
get called before you UI
gets layout. 这是因为在UI
获取布局之前,将调用viewDidload
。 so, if you want any animation related you scaling
any object then you should use viewDidAppear
instead of viewDidload
. 因此,如果您希望与任何动画相关联并scaling
任何对象,则应使用viewDidAppear
而不是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. 现在,如果您只想在用户启动应用程序时一次动画,而不是在用户回到第一个屏幕后浏览时,那么您应该设置一些flag
并将其值存储在某个位置以进行管理。
So, take a try in viewDidAppear
instead of viewDidload
! 因此,尝试用viewDidAppear
代替viewDidload
!
Update : 更新:
I have made one demo something like your setup and it works fine in viewDidload
also. 我做了一个演示,类似您的设置,它在viewDidload
也能正常工作。 main issue is your duration is very small for viewdidload
to run it. 主要问题是您的持续时间非常短, viewdidload
才能运行它。
Once try to change your duration like 2.0
and you will found your animation working perfact! 一旦尝试将持续时间更改为2.0
,您就会发现动画效果完美!
可能只是加载了先前实现的设备缓存,请尝试从设备中删除该应用程序,然后再次运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.