在动画中心保留背景图像

时间:2015-06-25 21:55:40

标签: ios swift uiviewanimation

我有动画设置将图像大小调整为原始大小的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")

我需要设置一个新动画,以便在动画发生时连续居中按钮吗?

请帮忙

尼基尔

1 个答案:

答案 0 :(得分:0)

将图层的属性contentsGravity设置为kCAGravityCenter