Swift中的UIView动画不起作用,错误的参数错误 [英] UIView Animation in Swift not working, wrong arguments error
问题描述
我正在尝试制作动画并使用以下代码。我得到无法使用类型'的参数列表调用'animateWithDuration'(FloatLiteralConvertible,delay:FloatLiteralConvertible,options:UIViewAnimationOptions,animations :() - >() - > $ T4,completion:(Bool) - >(Bool) - > $ T5)'错误。
I'm trying to do an animation and used the below code. I'm getting "Cannot invoke 'animateWithDuration' with an argument list of type '(FloatLiteralConvertible, delay: FloatLiteralConvertible, options: UIViewAnimationOptions, animations: () -> () -> $T4, completion: (Bool) -> (Bool) -> $T5)'" Error.
这意味着我使用了错误的参数。我错了。请帮忙。我无法真正解决它。
This means I'm using wrong arguments. I could be wrong. Please help in this. I couldn't really resolve it.
var basketTopFrame = CGRect()
basketTopFrame = dropPlace.frame
var mytimer : NSTimer = NSTimer .scheduledTimerWithTimeInterval(2.0, target: self, selector: "restart", userInfo: nil, repeats: false)
UIView.animateWithDuration(1.0, delay: 0.1, options: UIViewAnimationOptions.CurveEaseIn , animations: { var pickPlace = basketTopFrame }, completion: {(finished: Bool) in mytimer })
提前致谢。
推荐答案
如果只有一个语句,则闭包会自动返回。因为在你的情况下它返回 NSTimer
而不是 Void
。您提供的闭包与签名闭包不匹配。例如,您必须在 myTimer
上调用方法来解决此问题:
Closures have auto return if there is only one statement. Due to that in your case it is returning NSTimer
and not Void
. Your provided closure doesn't match signature closure. You have to call method on myTimer
, for example, to fix this issue:
UIView.animateWithDuration(1.0, delay: 0.1, options: UIViewAnimationOptions.CurveEaseIn,
animations: {
var pickPlace = basketTopFrame
},
completion: { (finished: Bool) in
mytimer.fire()
}
)
这篇关于Swift中的UIView动画不起作用,错误的参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!