In my xcode project I have an UIImage. I want to make it shaking (animation) from left to right a little bit. I wrote this code, however, its not working.
-(void
From Corona answer
Give shake animation in multiple buttons and also in views SWIFT3
for view animation just change extension UIButton to extension UIView
extension UIButton
{
func shakeAnim ()
{
let shake:CABasicAnimation = CABasicAnimation(keyPath: "position")
shake.duration = 0.1
shake.repeatCount = 2
shake.autoreverses = true
let from_point:CGPoint = CGPoint(x:self.center.x - 5,y: self.center.y)
let from_value:NSValue = NSValue(cgPoint: from_point)
let to_point:CGPoint = CGPoint(x:self.center.x + 5,y: self.center.y)
let to_value:NSValue = NSValue(cgPoint: to_point)
shake.fromValue = from_value
shake.toValue = to_value
self.layer.add(shake, forKey: "position")
}
}