【问题标题】:UIButton doesn't "blink" on every tapUIButton 不会在每次点击时“闪烁”
【发布时间】:2019-01-10 21:53:40
【问题描述】:

我在 UIView 中有 3 个 UIButtons,它们具有相同的文本颜色和相同的背景颜色。在点击时,他们三个都会触发相应的事件。但只有一个响应触摸“闪烁”。另外两个会发生什么?他们有时(但很少)有“眨眼”行为,但touch up inside event 总是在点击时触发。

按钮添加在storyboard:

【问题讨论】:

  • 然后设置高亮状态的背景颜色
  • @ktrkathi 我刚刚尝试了你的建议。我继承了 UIButton 并覆盖了 isHighlighted var 。我遇到了类似的问题。它只是有时(很少)突出显示。 touch event 每次都会触发。

标签: ios uibutton


【解决方案1】:
 func btnFlash_Clicked(sender: AnyObject) {
     if !flashing{
        callButton.alpha = 1.0
        UIView.animate(withDuration: 0.5, delay: 0.0, options: [.allowUserInteraction], animations: {() -> Void in
            callButton.alpha = 0.5
        }, completion: {(finished: Bool) -> Void in
        })

        flashing = true
     } else{
        flashing = false
        callButton.alpha = 0.5
        UIView.animate(withDuration: 0.5, delay: 0.0, options: [.allowUserInteraction], animations: {() -> Void in
            callButton.alpha = 1.0
        }, completion: {(finished: Bool) -> Void in
        })

【讨论】:

  • 我认为您对按钮的 alpha 进行动画处理的想法效果很好,但我不理解 flashing 变量和检查。你能再解释一下吗?
【解决方案2】:

我会将按钮类型设置为 UIButtonTypeCustom 以停止闪烁。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 2015-10-29
    相关资源
    最近更新 更多