OGeek|极客世界-中国程序员成长平台

标题: iphone - 更新 UIButton 的背景时延迟 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 21:10
标题: iphone - 更新 UIButton 的背景时延迟

我正在使用 setBackgroundImage:forState: 来更新 UIButton 的背景。背景更新,但仅在几秒钟后。这里显然有一些刷新周期在起作用,但我无法准确找到问题所在。我尝试使用 setNeedsRefresh 和 setNeedsDisplay 没有任何结果。

如何瞬间改变 UIButton 背景?

谢谢



Best Answer-推荐答案


当您尝试在后台线程(例如,在委托(delegate)回调中)执行 UIKit 操作时,通常会导致此类奇怪的延迟。试试这个:

dispatch_async(dispatch_get_main_queue(), ^{
    // set your button background here
});

关于iphone - 更新 UIButton 的背景时延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10702156/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4