UIViewAnimationOptions错误从Swift 1迁移到Swift 2

时间:2015-09-29 16:42:12

标签: swift uiview

我刚刚将Xcode更新为7.0.1,因此也将Swift从Swift 1更新为 斯威夫特2.

更新完成后我遇到了很多错误,这是我无法修复的问题之一。如果你能为我解决这个问题真的很好。

错误消息显示:

  

Nil与预期类型UIViewAnimationOption'

不兼容
UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 6, options: nil, animations: ({

}), completion: nil)

3 个答案:

答案 0 :(得分:1)

使用UIViewAnimationOptions

options:属性对象
UIView.animateWithDuration(2, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 6, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

}, completion: nil)

答案 1 :(得分:0)

您可以这样使用:

UIView.animateWithDuration(0, delay: 0, usingSpringWithDamping: 0, initialSpringVelocity: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in

        }) { (finished: Bool) -> Void in

    }

UIView.animateWithDuration(0, delay: 0, usingSpringWithDamping: 0, initialSpringVelocity: 0, options: [UIViewAnimationOptions.CurveEaseInOut, UIViewAnimationOptions.Autoreverse], animations: { () -> Void in

        }, completion: nil)

答案 2 :(得分:0)

在Swift 2中,UIViewAnimationOption被声明为非可选。因此它不能是nil。等效于无选项是通用初始化程序

... options: UIViewAnimationOption() ...

或一对空括号

... options: [] ...
相关问题