Swift 3 动画:代码运行但没有视觉效果

Swift 3 Animation: code runs but there is no visual efect

我的动画代码已执行(我可以在任何动画行上使用断点来停止执行)但我在视觉上看不到任何东西。它甚至需要我设置的第二个时间什么都不做,它只是执行下一个 segue。我的文本字段应该会在 1 秒内淡出。

        //animate text fields (fade till dissappear)
        let animationTextFields = {() -> Void in
            self.firstField.alpha = 0.0
            self.secondField.alpha = 0.0
            self.thirdField.alpha = 0.0
            self.fourthField.alpha = 0.0

        }


        UIView.animate(withDuration: 1.0, animations: animationTextFields)


        //animate next button (flies right)

        //animate back button (flies left)

        //animate "please" label (flies up)





        self.performSegue (withIdentifier: "SegueToMainNavigation", sender: self)

如您所见,我还需要进一步的动画,但一次一个步骤。

知道为什么我的动画没有出现吗?

尝试在 animationTextFields 闭包中写入 self.layoutIfNeeded()

在动画完成后进行转场..

  UIView.animate(withDuration: 1.0, delay: 0.0, options: [], animations: animationTextFields, completion: { (finished: Bool) in
            self.performSegue (withIdentifier: "SegueToMainNavigation", sender: self)
    })

试试这个代码

UIView.animate(withDuration: 0.3)
{

 self.performSegue (withIdentifier: "SegueToMainNavigation", sender: self)          
}

如果您希望它们同时发生,您可以通过 transitionCoordinator:

performSegue(withIdentifier: "SegueIdentifier", sender: self)

transitionCoordinator?.animate(alongsideTransition: { context in
    UIView.animate(withDuration: 1) {
        self.label.alpha = 0         // fade out
    }
}, completion: { context in
    self.label.alpha = 1             // if you want, when done, make it visible again so when you return back here you can see it
})