gpt4 book ai didi

ios - 按钮背景颜色动画禁用触摸(IOS)

转载 作者:行者123 更新时间:2023-11-28 10:20:32 25 4
gpt4 key购买 nike

我正在开发一个读取二维码的 Swift 应用程序。当应用程序识别出二维码时,它需要开始动画按钮的背景颜色以吸引用户的注意力。动画按预期工作,但按钮似乎不再响应触摸事件。如果我禁用动画,按钮将正常工作。我应该如何解决这个问题?谢谢!

动画代码如下:

var getCoordButtonAnimationRunning = false
let secondBackgroundColor = UIColor(red: 137.0/255.0, green: 205.0/255.0, blue: 237.0/255.0, alpha: 1.0)
func animateCoordButton() {
if !getCoordButtonAnimationRunning && !initiatedAnimationStop {
getCoordButtonAnimationRunning = true

UIView.animateWithDuration(0.5, delay: 0.0, options: [.Autoreverse, .Repeat],
animations: {
self.getCoordinatesButton.backgroundColor = self.secondBackgroundColor
},
completion: { finished in
UIView.animateWithDuration(0.5, delay: 0.0, options: [],
animations: {
self.getCoordinatesButton.backgroundColor = self.getCoordinatesButtonColor
},
completion: { finished in
self.getCoordButtonAnimationRunning = false
self.initiatedAnimationStop = false
})
})
}
}

var initiatedAnimationStop = false
func stopAnimatingCoordButton() {
if !initiatedAnimationStop {
initiatedAnimationStop = true
getCoordinatesButton.layer.removeAllAnimations()
}
}

最佳答案

您需要将 .AllowsUserInteraction 选项添加到您的动画中。默认情况下,动画 View 会禁用用户交互。

关于ios - 按钮背景颜色动画禁用触摸(IOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35746386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com