UIButtons在animation过程中没有响应 – iOS Swift 3

我正在构build一个计算器应用程序,当我点击button时,有一个简短的animation。 问题是button在animation时不响应,这使得应用程序感觉迟缓。

我发现Objective-C的一些解决scheme使用:

UIViewAnimationOptionAllowUserInteraction 

但是Swift 3没有,我的代码如下所示:

 func myButton () { sender.layer.backgroundColor = firstColor sender.setTitleColor(UIColor.white, for: UIControlState.normal) UIView.animate(withDuration: 0.5) { sender.layer.backgroundColor = secondColor } } 

调用UIView的不同方法:

 func myButton () { sender.layer.backgroundColor = firstColor sender.setTitleColor(UIColor.white, for: UIControlState.normal) UIView.animate(withDuration: 0.5, delay: 0.0, options: .allowUserInteraction, animations: { sender.layer.backgroundColor = secondColor }, completion: nil) }