【问题标题】:Variable used within its own initial value in Swift 5在 Swift 5 中在其自己的初始值中使用的变量
【发布时间】: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: animationsanimations() 中显示错误:

变量在自己的初始值内使用

【问题讨论】:

标签: ios swift


【解决方案1】:

初始化时不能调用自身。 你也可以这样实现。

var animations:(() -> Void)!

animations = {
    animations()
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 2017-04-19
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多