ios Nil 与预期的参数类型 UIViewAnimationOptions 不兼容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32638488/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 07:40:43  来源:igfitidea点击:

Nil is not compatible with expected argument type UIViewAnimationOptions

iosuiviewswift2

提问by Brenner

I just started programming and following a tutorial online I was unable to create this animation. Can anyone tell me why it's saying:

我刚开始编程,按照在线教程我无法创建这个动画。谁能告诉我为什么它说:

Nil is not compatible with expected argument type UIViewAnimationOptions

Nil 与预期的参数类型 UIViewAnimationOptions 不兼容

and how to fix it?

以及如何解决它?

view.addSubview(myFirstLabel)

UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: nil, animations: {

    self.myFirstLabel.center = CGPoint(x: 100, y:40 + 200)

}, completion: nil)

回答by AaoIi

You may replace options: nilwith options: []should make the error goes way.

您可以替换options: niloptions: []应该使错误消失。

Good luck !

祝你好运 !

回答by Jelly

UIViewAnimationOptions is an enum backed by integers. You should pass 0. Hereis the doc for the enum.

UIViewAnimationOptions 是一个由整数支持的枚举。您应该传递 0。是枚举的文档。

回答by Mohmmad S

It's because UIViewAnimationOptionsis an OptionSettype, not Optional typeOptionSetaccording to apple

这是因为UIViewAnimationOptions是一种OptionSet类型,而不是Optional typeOptionSet根据苹果

You use the OptionSet protocol to represent bitsettypes, where individual bits represent members of a set.

您使用 OptionSet 协议来表示bitset类型,其中各个位表示集合的成员。

it's mainly used to create a combined flag from the current flags inside the set, in your case animation flags or types we can call them, this will give you the ability to combine options to make the final desired option, there are about 23option, however in your case you can just pass an empty OptionSetas []

它主要用于从集合中的当前标志创建组合标志,在您的情况下,我们可以调用动画标志或类型,这将使​​您能够组合选项以制作最终所需的选项,大约有23 个选项,但是在你的情况下,你可以传递一个空 OptionSet作为[]