简体   繁体   English

紧接着segue之后如何立即运行动画?

[英]How to run an animation after segue immediately without any delay?

I am running a slidein animation on an inner view of a new UIViewController which has been load. 我在已加载的新UIViewController的内部视图上运行幻灯片动画。 The problem is, because the animation can only be excecuted in ViewDidAppear() , that there is a delay between when the ViewController did load and when the animation starts. 问题是,因为只能在ViewDidAppear()执行动画,所以ViewController加载的时间和动画开始的时间之间存在延迟。 Because of this delay, it seems that the app has performance issues. 由于存在此延迟,因此该应用似乎存在性能问题。

How can this problem be solved? 如何解决这个问题?

Use viewWillAppear should solve your problem. 使用viewWillAppear应该可以解决您的问题。

The animation code should be asynchronously because inside of viewWillAppear the view hasn't appeared yet 动画代码应该是异步的,因为在viewWillAppear内部视图尚未出现

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    DispatchQueue.main.async {
        self.appearanceAnimation()
    }
}

func appearanceAnimation() {
    //Add animaton here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM