UIView Animation in Swift not working, wrong arguments error

夙愿已清 提交于 2019-12-06 01:08:41

问题


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 })

Thanks in advance.


回答1:


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()
    }
)


来源:https://stackoverflow.com/questions/26397164/uiview-animation-in-swift-not-working-wrong-arguments-error

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