UIButtons are not responding during animation - iOS Swift 3(UIButtons 在动画期间没有响应 - iOS Swift 3)
本文介绍了UIButtons 在动画期间没有响应 - iOS Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个计算器应用程序,当我点击按钮时会出现一个简短的动画.问题是按钮在动画时没有响应,这让应用感觉迟钝.
I'm building a calculator app, when I tap on the buttons there is a short animation. The problem is the buttons do not respond while they are animating, which makes the app feel laggy.
我找到了一些针对 Objective-C 的解决方案:
I found some solutions for Objective-C using:
UIViewAnimationOptionAllowUserInteraction
但 Swift 3 没有,我的代码如下所示:
but nothing for Swift 3, my code looks like this:
func myButton () {
sender.layer.backgroundColor = firstColor
sender.setTitleColor(UIColor.white, for: UIControlState.normal)
UIView.animate(withDuration: 0.5) {
sender.layer.backgroundColor = secondColor
}
}
推荐答案
调用UIView的不同方法:
Call different method of 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)
}
这篇关于UIButtons 在动画期间没有响应 - iOS Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:UIButtons 在动画期间没有响应 - iOS Swift 3


猜你喜欢
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- UITextView 内容插图 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- URL编码Swift iOS 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01