let myAnimation: CAKeyframeAnimation = CAKeyframeAnimation.init() //创建动画
myAnimation.removedOnCompletion = false //设置这个属性为false,当应用退到后台再进来的时候保证动画还存在
let left: CGFloat = CGFloat(-M_PI_2) * 0.01 //这个值控制动画的抖动范围(振幅)
let right: CGFloat = CGFloat(M_PI_2) * 0.01
myAnimation.keyPath = "position" //设置动画的样式
myAnimation.keyPath = "transform.rotation"
myAnimation.values = [(left),(right),(left)]
myAnimation.duration = 0.15 //执行一次动画的时间
myAnimation.repeatCount = MAXFLOAT //执行无限次
uiimageView.layer.addAnimation(myAnimation, forKey: nil) //添加动画到控件的layer层