在Swift中动画化视图

use*_*253 6 swift xcode6 ios8

我一直试图使用swift使用弹簧动画为UIView制作动画.当我使用目标C时,我能够实现它,但是我在swift中遇到错误.这是动画:

UIView.animateWithDuration(3,
usingSpringWithDamping: 0.3,
initialSpringVelocity: 3.0,
animations:{
viewToAnimate.frame.offset(dx: 0, dy: 100.0)},
completion: nil)
Run Code Online (Sandbox Code Playgroud)

编译器给我一个错误说

Could not find an overload for 'animateWithDuration' that accepts supplied arguments. 
Run Code Online (Sandbox Code Playgroud)

如果我删除"usingSpringWithDamping:0.3,initialSpringVelocity:3.0",它编译和动画很好.如何快速制作弹簧动画?

Mic*_*lum 16

你错过了一个参数.该方法也需要延迟作为输入.

UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.3, initialSpringVelocity: 3.0, options: UIView.AnimationOptions.curveEaseInOut, animations: ({
    // do stuff
}), completion: nil)
Run Code Online (Sandbox Code Playgroud)


Mas*_*eni 10

试试这个:

UIView.animateWithDuration(0.7, delay: 0.0, usingSpringWithDamping: 0.5,
initialSpringVelocity: 0.5, options: [], animations: 
{
    self.yourView.transform = CGAffineTransformMakeScale(1, 1)
}, completion: nil)
Run Code Online (Sandbox Code Playgroud)

对于任何其他类似的问题,请查看我在GitHub上的示例