我很难让Swift 的积木正常工作.下面是一个成功的示例(没有完成挡路):
UIView.animateWithDuration(0.07) {
self.someButton.alpha = 1
}
或者,也可以不使用尾部闭合:
UIView.animateWithDuration(0.2, animations: {
self.someButton.alpha = 1
})
但一旦我try 添加完成块,它就不起作用了:
UIView.animateWithDuration(0.2, animations: {
self.blurBg.alpha = 1
}, completion: {
self.blurBg.hidden = true
})
自动完成功能给了我completion: ((Bool) -> Void)?
分,但我不确定如何让它工作.我还try 了尾部闭合,但得到了相同的错误:
! Could not find an overload for 'animateWithDuration that accepts the supplied arguments
SWIFT 3/4更新:
// This is how I do regular animation blocks
UIView.animate(withDuration: 0.2) {
<#code#>
}
// Or with a completion block
UIView.animate(withDuration: 0.2, animations: {
<#code#>
}, completion: { _ in
<#code#>
})
我没有使用尾部闭合来完成挡路,因为我认为它不够清晰,但是如果你喜欢它,你可以看到Trevor's answer below.