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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)