gpt4 book ai didi

ios - Swift 中 UIImageView 的无限摇动动画

转载 作者:可可西里 更新时间:2023-11-01 02:23:09 25 4
gpt4 key购买 nike

我正在尝试让 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")

最佳答案

替换

let coffeeShakeAnimation = CABasicAnimation(keyPath: "transform")

let coffeeShakeAnimation = CABasicAnimation(keyPath: "position")

会摇晃

关于ios - Swift 中 UIImageView 的无限摇动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29684754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com