UIButtons在动画期间没有响应 - iOS Swift 3

时间:2016-12-18 12:25:22

标签: ios swift animation uibutton

我正在构建一个计算器应用程序,当我点击按钮时会有一个简短的动画。问题是按钮在动画时没有响应,这使得app感觉很迟钝。

我使用以下方法找到了Objective-C的一些解决方案:

vertex.createHttpServer

但没有Swift 3,我的代码看起来像这样:

UIViewAnimationOptionAllowUserInteraction

1 个答案:

答案 0 :(得分:6)

调用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)
}