我有一个关于反转 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
}
关于ios - UIButton反转并发问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34551168/