简体   繁体   English

在Swift 5中以其自身初始值使用的变量

[英]Variable used within its own initial value in Swift 5

I try to write an animation with Swift 5, following are some codes 我尝试用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()
    }
}

But in animations: animations and animations() it shows error: 但是在animations: animationsanimations()显示错误:

Variable used within its own initial value 在其初始值内使用的变量

You can not call itself when initializing. 初始化时您不能自称。 You can achieve it like this also. 您也可以这样实现。

var animations:(() -> Void)!

animations = {
    animations()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM