【问题标题】:Button background color animation disable touch (IOS)按钮背景颜色动画禁用触摸(IOS)
【发布时间】:2016-03-02 11:49:11
【问题描述】:

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

动画代码如下:

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()
    }
}

【问题讨论】:

    标签: ios swift animation


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-05-16
      • 1970-01-01
      • 2015-04-06
      • 1970-01-01
      • 1970-01-01
      • 2014-11-06
      • 2012-06-16
      • 1970-01-01
      • 2013-06-24
      相关资源
      最近更新 更多