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

标签 ios swift animation uibutton

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

我找到了一些针对 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/

相关文章:

ios - 当部署目标设置为 iOS 8.0 时,App Store 仅允许 iOS 10 或更高版本

iphone - 如何在 iOS 上的 subview UITableView 上设置编辑按钮

ios - 如何获取表格 View 单元格中每行字符串文本的高度?

swift - 返回对象比原始类型有什么好处?

iphone - Windows Phone 7 UI (Metro) 可以在 iOS 上使用吗?

iOS - 使按钮 subview 不受 Super View 的双击识别器的影响

swift - 如何获取Marker的经纬度Swift

jquery - 有什么办法可以从下面给出的动画功能中获取 top 的当前值

ios - animateWithDuration(有时)跳到最终位置而不使用动画

ios - 如何在 iOS 应用程序中使用标准经典蓝牙配置文件?