Swift 调用一个函数作为另一个函数的操作

Swift 调用一个函数作为另一个函数的操作,swift,Swift,我试图让一个函数作为另一个函数的操作运行,但它运行得太早了。我试图在文本淡出后调用nameRequest()函数,但奇怪的是,在文本淡出之前,我可以在屏幕的一角看到文本,然后当文本淡出时,它只是移动到正确的CG点。我对此感到非常困惑。如果有人能提供一些见解,我将不胜感激。多谢各位 func fadeViewInThenOut(view : UILabel, delay: TimeInterval) { let animationDuration = 1.00

我试图让一个函数作为另一个函数的操作运行,但它运行得太早了。我试图在文本淡出后调用
nameRequest()
函数,但奇怪的是,在文本淡出之前,我可以在屏幕的一角看到文本,然后当文本淡出时,它只是移动到正确的CG点。我对此感到非常困惑。如果有人能提供一些见解,我将不胜感激。多谢各位

func fadeViewInThenOut(view : UILabel, delay: TimeInterval) {

                let animationDuration = 1.00

                // Fade in the view
                UIView.animate(withDuration: animationDuration, delay: 1, animations: { () -> Void in
                    view.alpha = 1
                    }) { (Bool) -> Void in

                        // After the animation completes, fade out the view after a delay

                        UIView.animate(withDuration: animationDuration, delay: delay, animations: { () -> Void in
                            view.alpha = 0
                            nameRequest()
                        }, completion: nil)
                }
            }
            fadeViewInThenOut(view: newwelcomeLabel, delay: 5)
        }
        newWelcomeLabel()

        func nameRequest() {
            let namerequestLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 500, height: 50))
            namerequestLabel.text = "what's your name?"
            namerequestLabel.textAlignment = .center
            namerequestLabel.center = CGPoint(x: self.view.center.x/1.3, y: self.view.center.y/2)
            namerequestLabel.font = UIFont.boldSystemFont(ofSize: 30)
            self.view.addSubview(namerequestLabel)
        }
    }

无法确定代码在动画块中的执行顺序。您会看到标签立即出现,因为
nameRequest
addSubview
不可设置动画。这些方法将立即执行,您的可设置动画的属性,如
view.alpha
namerequestLabel.center
,将根据您提供给
UIView.animate的参数进行操作(持续时间:)
如果您确实希望
nameRequest
在动画之后运行,则应实现
completion
处理程序,并从那里调用
nameRequest