[英]Variable used within its own initial value in Swift 5
我嘗試用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()
顯示錯誤:
在其初始值內使用的變量
初始化時您不能自稱。 您也可以這樣實現。
var animations:(() -> Void)!
animations = {
animations()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.