淡入淡出链动画不起作用:仅视图淡入

时间:2019-06-13 22:59:55

标签: swift animation fade uianimation

我正在尝试使用淡入淡出动画链来按顺序淡入我的对象。首先,我使视图淡入,然后其余标签也应随之而来。标签位于堆栈视图中,其Alpha为1.0。我确保所有其他alpha值都从零开始。这是我的功能:

func fadeIn() {
    UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
        self.view.alpha = 1.0
    }, completion: { finished in
        if finished {
            UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
                self.gameOverLabel.alpha = 1.0
            }, completion: { finished in
                if finished {
                    UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
                        self.scoreLabel.alpha = 1.0
                    }, completion: { finished in
                        if finished {
                            UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
                                self.highScoreLabel.alpha = 1.0
                            }, completion: { finished in
                                if finished {
                                    UIView.animate(withDuration: 0.5, delay: 0.0, options: UIView.AnimationOptions.curveEaseIn, animations: {
                                        self.restartButton.alpha = 1.0
                                    }, completion: nil)
                                    //breakpoint set here
                                }
                            })
                        }
                    })
                }
            })
        }
    })
}

我在所有动画完成后设置了一个断点(如上所示),并且所有alpha值均为1.0。但是,设备仅给我一个空白的白色屏幕。发生了什么事?

P.S。显示此视图控制器后立即调用该函数:

view.present(vc, animated: false, completion: {
    vc.fadeIn()
})

1 个答案:

答案 0 :(得分:0)

尝试将protected void Session_Start(object sender, EventArgs e) { Session.Timeout = 60000; } 选项添加到动画中。像这样:

.layoutSubviews

从Apple的文档中,此选项可以执行以下操作:

  

在提交时对子视图进行布局,以便它们与父视图一起动画化。

可能是由于提交时尚未在提交时布置子视图。