首页 > 解决方案 > 过早调用完成处理程序

问题描述

我试图在标签缩小后运行这个完成处理程序,但它在函数的一开始就被调用。我看过一些教程并阅读了一些文档,但我似乎无法弄清楚我的代码有什么问题。

func fadeViewInThenOut(view : UILabel, delay: TimeInterval, completion: () -> () ) {
    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
        }, completion: nil)
    }

    completion()
}

fadeViewInThenOut(view: newwelcomeLabel, delay: 5) {
    print("hello")
}

标签: swifthandlercompletion

解决方案


推荐阅读