简体   繁体   English

应用程序启动动画仅在从Xcode运行时有效

[英]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.

相关问题 不从Xcode运行时应用程序崩溃,但从Xcode运行时运行正常 - Application crashes when not running from Xcode but works fine when run from Xcode iOS 应用程序被 WatchDog 崩溃,但在从 Xcode 运行时可以正常工作 - iOS app crashes by WatchDog but works when running from Xcode xcode 6中启动屏幕中的动画 - Animation in Launch Screen in xcode 6 运行/调试时,Xcode 4.5不会在模拟器或Mac应用程序中启动iOS应用程序 - Xcode 4.5 doesn't launch iOS application in simulator or mac app when running/debugging 运行应用程序时xCode崩溃 - xCode Crashing When Running Application iOS-仅在直接在模拟器上运行,但在调试或通过Xcode运行时,应用程序才能正常运行 - iOS - Application crashes only when running directly on simulator but working fine while debugging or running through Xcode 使用Xcode 7构建并提交时,iOS Testflighted App在仅运行iOS8的iPhone 4s上的启动屏幕上崩溃 - iOS Testflighted App crashes at the launch screen, on iPhone 4s running iOS8 only, when built+submitted with Xcode 7 状态恢复仅在连接到Xcode时有效 - State restoration only works when connected to Xcode Flutter iOS 应用程序在从 ipa 文件启动时崩溃,但从 xCode 运行时工作正常 - Flutter iOS app crashes on start from ipa file, but works fine when running from xCode 运行 UI 测试时 Fastlane 扫描“无法合成事件”,适用于 Xcode - Fastlane Scan “Failed to synthesize event” when running UI Tests, works from Xcode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM