如何更改每个用户的快速点击上的Uibutton BackgroundColor?
我有一个自定义键盘视图。
当用户按下uibuttons
时,我会更改其背景彩色以模仿\ out效果。
这是我使用的代码:
class NumpadButton: UIButton {
override var isHighlighted: Bool {
didSet {
if isHighlighted {
backgroundColor = UIColor(named: "FadeGrayColor")
} else {
UIView.animate(withDuration: 0.2) {
default: self.backgroundColor = UIColor(named: "NumpadGrayColor")
}
}
}
}
}
这是外观:

问题:
如果您非常快地点击同一按钮,您将不会看到\ out 背景颜色中的淡出
在第一个之后更改taps,因为uiview.animate(dusturation:0.2)
应该结束,然后可以再次运行代码。第二个点击可以更快,动画零件将结束。
如果您打开标准的iPhone计算器应用程序,并尝试执行相同的操作,您会发现它将在上删除,无论它多快吗点击。
如果我删除uiview.animate
部分,那么淡出将是直的,我想避免。
我还与使用touchedbegan()
和thinededed()
方法相同,但它具有相同的效果...
我如何从计算器应用中复制行为并在每个代码上运行轻敲?
I have a custom keyboard view.
When user presses one of the UIButtons
I change its backgroundColor to imitate fade in\out effect.
Here is the code I use:
class NumpadButton: UIButton {
override var isHighlighted: Bool {
didSet {
if isHighlighted {
backgroundColor = UIColor(named: "FadeGrayColor")
} else {
UIView.animate(withDuration: 0.2) {
default: self.backgroundColor = UIColor(named: "NumpadGrayColor")
}
}
}
}
}
Here is how it looks:
The problem:
If you tap on the same button very-very fast you won't see a fade in\out background color
change for taps after the first one, because UIView.animate(withDuration: 0.2)
should be ended and then the code can be run again. The second tap can be faster that animate part will end.
If you open standard iPhone Calculator app and try to do the same you'll notice it will fade in\out on every tap, no matter how fast it is.
If I remove UIView.animate
part then fade out will be straight, which I would like to avoid.
I tied to use also touchedBegan()
and touchedEnded()
methods but it has the same effect...
How can I replicate behaviour from Calculator app and run above code on every tap?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
见下文:
}
See below:
}