Nil is not compatible with expected argument type UIViewAnimationOptions

左心房为你撑大大i 提交于 2019-12-20 09:46:32

问题


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

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)

回答1:


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

Good luck !




回答2:


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




回答3:


It's because UIViewAnimationOptions is an OptionSet type, not Optional type OptionSet according to apple

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

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 23 option, however in your case you can just pass an empty OptionSet as []



来源:https://stackoverflow.com/questions/32638488/nil-is-not-compatible-with-expected-argument-type-uiviewanimationoptions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!