我正在构建一个计算器应用程序,当我点击按钮时会出现一个简短的动画。问题是按钮在动画时没有响应,这让应用程序感觉迟钝。
我找到了一些针对 Objective-C 的解决方案:
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)
}
关于ios - UIButtons 在动画期间没有响应 - iOS Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41208298/