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
Nil is not compatible with expected argument type UIViewAnimationOptions
提问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: nil
with options: []
should make the error goes way.
您可以替换options: nil
为options: []
应该使错误消失。
Good luck !
祝你好运 !
回答by Jelly
回答by Mohmmad S
It's because UIViewAnimationOptions
is an OptionSet
type, not Optional type
OptionSet
according to apple
这是因为UIViewAnimationOptions
是一种OptionSet
类型,而不是Optional type
OptionSet
根据苹果
You use the OptionSet protocol to represent
bitset
types, 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 OptionSet
as []
它主要用于从集合中的当前标志创建组合标志,在您的情况下,我们可以调用动画标志或类型,这将使您能够组合选项以制作最终所需的选项,大约有23 个选项,但是在你的情况下,你可以传递一个空 OptionSet
作为[]