📜  UIView Shake - 任何代码示例

📅  最后修改于: 2022-03-11 14:58:25.278000             🧑  作者: Mango

代码示例1
extension UIView {
  
  func shake() {
    let animation = CABasicAnimation(keyPath: "position")
    animation.duration = 0.07
    animation.repeatCount = 3
    animation.autoreverses = true
    animation.fromValue = NSValue(CGPoint: CGPointMake(self.center.x - 10, self.center.y))
    animation.toValue = NSValue(CGPoint: CGPointMake(self.center.x + 10, self.center.y))
    self.layer.addAnimation(animation, forKey: "position")
  }

}