View animation in Swift

I am trying to animate a UIView with spring animations using swift. I can achieve this when I use objective C, however I get an error quickly. This is the animation:

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

The compiler gives me an error message

 Could not find an overload for 'animateWithDuration' that accepts supplied arguments. 

If I remove "usingSpringWithDamping: 0.3, initialSpringVelocity: 3.0," it compiles and animates perfectly. How can I make spring animations in swift?

+6
source share
2 answers

You have missed the option. The method also takes a delay as input.

 UIView.animate(withDuration: 1.0, delay: 0.0, usingSpringWithDamping: 0.3, initialSpringVelocity: 3.0, options: UIView.AnimationOptions.curveEaseInOut, animations: ({ // do stuff }), completion: nil) 
+16
source

Try the following:

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

For any other similar issues, consider my GitHub example.

+10
source

Source: https://habr.com/ru/post/970661/


All Articles