繁体   English   中英

UIButton反向并发问题

[英]UIButton Inversion Concurrency issue

我有一个关于反转uibutton颜色的问题。 我正在尝试在文本颜色和背景颜色之间切换; 但是,当用户尝试快速按下时,颜色会停止反转。 我相信这是一个并发问题。 我尝试使用锁和操作队列。 有人有什么建议吗?

这是我的代码

  func invertStartButton(){
    let currentBackGroundColor:UIColor? = self.startButton.backgroundColor
    print(currentBackGroundColor)
    objc_sync_enter(currentBackGroundColor)
    defer{
        objc_sync_exit(currentBackGroundColor)
    }
    self.startButton.backgroundColor = self.startButton.titleLabel?.textColor
    print(self.startButton.backgroundColor)

    self.startButton.setTitleColor(currentBackGroundColor, forState: UIControlState.Normal)
}

最简单的解决方案是在更改过程中禁用按钮:

@IBAction func invertButton(sender: UIButton) {
    sender.enabled = false
    // invert
    sender.enabled = true
}

问题与实例变量有关。 因此,为了解决此问题,我使用了两个带有布尔值的硬编码代码进行切换

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM