【发布时间】:2019-04-16 05:18:26
【问题描述】:
我尝试用 Swift 5 写一个动画,下面是一些代码
let animations:(() -> Void) = {
self.keyboardOPT.transform = CGAffineTransform(translationX: 0,y: -deltaY)
if duration > 0 {
let options = UIView.AnimationOptions(rawValue: UInt((userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as! NSNumber).intValue << 16))
UIView.animate(withDuration: duration, delay: 0, options: options, animations: animations, completion: nil)
} else {
animations()
}
}
但在animations: animations 和animations() 中显示错误:
变量在自己的初始值内使用
【问题讨论】:
-
你的块常量的名字是
animations=>let animations:...。在此块内,在您的else语句中,您还调用了animations()。所以你在块内调用块。你不能这样做。