我有动画设置,可将图像大小调整为原始大小的 1.3 倍左右。动画和一切都工作正常,但图像正在向左上方移动。这意味着图像的位置在调整大小时不居中。我该如何解决这个问题
这些是我设置的动画
var borderWidth:CABasicAnimation = CABasicAnimation(keyPath: "borderWidth")
borderWidth.fromValue = 0
borderWidth.toValue = 5
borderWidth.repeatCount = Float.infinity
sender.layer.borderWidth = 0
var increaseButtonHeight:CABasicAnimation = CABasicAnimation(keyPath: "bounds.size.height")
increaseButtonHeight.fromValue = sender.frame.size.height
increaseButtonHeight.toValue = sender.frame.size.height * 1.3
var increaseButtonWidth: CABasicAnimation = CABasicAnimation(keyPath: "bounds.size.width")
increaseButtonWidth.fromValue = sender.frame.size.width
increaseButtonWidth.toValue = sender.frame.size.width * 1.3
var boom:CAAnimationGroup = CAAnimationGroup()
boom.animations = [borderWidth,increaseButtonWidth, increaseButtonHeight]
boom.repeatCount = Float.infinity
boom.duration = 0.5
boom.autoreverses = true
sender.layer.addAnimation(boom, forKey: "boom")
我是否需要设置一个新的动画,以便在动画发生时使按钮连续居中?
请帮忙
尼基尔
最佳答案
将图层的属性contentsGravity
设置为kCAGravityCenter
关于ios - 将背景图像保持在动画的中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31061469/