swift - 过早调用完成处理程序
问题描述
我试图在标签缩小后运行这个完成处理程序,但它在函数的一开始就被调用。我看过一些教程并阅读了一些文档,但我似乎无法弄清楚我的代码有什么问题。
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")
}
解决方案
推荐阅读
- ios - Xcode项目添加视频文件,使用后删除
- javascript - 使用 Javascript 确定 Accept-Language HTTP 请求标头 - 或以其他方式确定用户的首选语言
- c# - Visual Studio 2017 命名参数语法突出显示?
- arrays - 如何比较一个数组中的对象
- mule - 如何检查有效载荷内的空数组?
- python - namedtuple 和 NamedTuple 有什么区别?
- java - 如何在 Gradle 插件中检查/读取 Java 文件
- python - Python HTTPSConnection 异常
- c# - 按钮循环 ASP.NET
- javascript - 在向 li 添加新课程之前删除课程