1

我是 Swift 的新手,我有这个扩展:

extension UIView.KeyframeAnimationOptions {
    init(animationOptions: UIView.AnimationOptions) {
        rawValue = animationOptions.rawValue
    }
}

由于 Swift 4.2rawValue = animationOptions.rawValue产生了这个警告:

Initializer for struct 'UIView.KeyframeAnimationOptions' must use "self.init(...)" or "self = ..." because the struct was imported from C

我使用这样的扩展名:

UIView.animateKeyframes(withDuration: 1.2, delay: 0.0, options: [.repeat, UIView.KeyframeAnimationOptions(animationOptions: .curveEaseOut)], animations: {
...
}

如何从 中修复此警​​告消息struct was imported from C

4

2 回答 2

2
于 2018-09-25T23:53:25.487 回答
0

你的代码从来都不正确。它应该是:

extension UIView.KeyframeAnimationOptions {
    init(animationOptions: UIView.AnimationOptions) {
        self.init(rawValue: animationOptions.rawValue)
    }
}

但是,这是个坏主意。您将一个枚举的选项强制转换为一个不相关的枚举。这将导致问题。

于 2018-09-25T23:49:44.350 回答