按钮背景颜色动画禁用触摸(IOS)

时间:2016-03-02 11:49:11

标签: ios swift animation

我正在开发一个读取QR码的Swift应用程序。当应用程序识别出QR码时,需要开始设置按钮背景颜色的动画以吸引用户的注意力。动画按预期工作,但按钮似乎不再响应触摸事件。如果我禁用动画,按钮正常工作。我应该如何解决这个问题?谢谢!

动画的代码如下:

var getCoordButtonAnimationRunning = false
let secondBackgroundColor = UIColor(red: 137.0/255.0, green: 205.0/255.0, blue: 237.0/255.0, alpha: 1.0)
func animateCoordButton() {
    if !getCoordButtonAnimationRunning && !initiatedAnimationStop {
        getCoordButtonAnimationRunning = true

        UIView.animateWithDuration(0.5, delay: 0.0, options: [.Autoreverse, .Repeat],
            animations: {
                self.getCoordinatesButton.backgroundColor = self.secondBackgroundColor
            },
            completion: { finished in
                UIView.animateWithDuration(0.5, delay: 0.0, options: [],
                    animations: {
                        self.getCoordinatesButton.backgroundColor = self.getCoordinatesButtonColor
                    },
                    completion: { finished in
                        self.getCoordButtonAnimationRunning = false
                        self.initiatedAnimationStop = false
                    })
            })
    }
}

var initiatedAnimationStop = false
func stopAnimatingCoordButton() {
    if !initiatedAnimationStop {
        initiatedAnimationStop = true
        getCoordinatesButton.layer.removeAllAnimations()
    }
}

1 个答案:

答案 0 :(得分:4)

您需要为动画添加.AllowsUserInteraction选项。默认情况下,动画视图会禁用用户交互。

相关问题