我试图让UIImageView无限期地动摇。
var coffeeImageView = UIImageView(image: UIImage(named: "coffee.png"))
coffeeImageView.frame = CGRectMake(100, self.view.frame.size.height - 100, 50, 50)
self.view.addSubview(coffeeImageView)
let coffeeShakeAnimation = CABasicAnimation(keyPath: "transform")
coffeeShakeAnimation.duration = 0.07
coffeeShakeAnimation.repeatCount = 20
coffeeShakeAnimation.autoreverses = true
coffeeShakeAnimation.fromValue = NSValue(CGPoint: CGPointMake(coffeeImageView.center.x - 10, coffeeImageView.center.y))
coffeeShakeAnimation.toValue = NSValue(CGPoint: CGPointMake(coffeeImageView.center.x + 10, coffeeImageView.center.y))
coffeeImageView.layer.addAnimation(coffeeShakeAnimation, forKey: "position")
答案 0 :(得分:1)
替换
let coffeeShakeAnimation = CABasicAnimation(keyPath: "transform")
通过
let coffeeShakeAnimation = CABasicAnimation(keyPath: "position")
它会动摇