小编Jr *_*Dev的帖子

如何在 UIImageView 上放置抖动动画

我正在尝试在 UIImageView 上添加永久摇动动画。我怎样才能控制它的动画时间呢?

 var coffeeImageView = UIImageView(image: UIImage(named: "coffee.png"))
        shakeImg.frame = CGRectMake(100, self.view.frame.size.height - 100, 50, 50)
        self.view.addSubview(coffeeImageView)

        let coffeeShakeAnimation = CABasicAnimation(keyPath: "position")
        coffeeShakeAnimation.duration = 0.07
        coffeeShakeAnimation.repeatCount = 20
        coffeeShakeAnimation.autoreverses = true
        coffeeShakeAnimation.fromValue = NSValue(cgPoint: CGPointMake(shakeImg.center.x - 10, shakeImg.center.y))
        coffeeShakeAnimation.toValue = NSValue(cgPoint: CGPointMake(shakeImg.center.x + 10, shakeImg.center.y))
        shakeImg.layer.add(coffeeShakeAnimation, forKey: "position")
Run Code Online (Sandbox Code Playgroud)

animation uiimage swift

1
推荐指数
1
解决办法
1332
查看次数

标签 统计

animation ×1

swift ×1

uiimage ×1