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

问题描述:

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

动画的代码如下:

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

您需要的.AllowsUserInteraction选项添加到您的动画。动画化视图默认禁用用户交互。