iphone - 更新 UIButton 背景时的延迟

标签 iphone ios uibutton delay setbackground

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

如何立即更改 UIButton 背景?

谢谢

最佳答案

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

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

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

相关文章:

ios - UIButton 随着文本的变化而变暗

ios - 如何绘制三角形的UIButton

iphone - 使用 APParallaxHeader 显示图像时出现问题

iphone - 你好 iPhone 版

iphone - 解析 NSStrings 以确保 XCode 中的 JSON 字符串格式正确

iphone - 使用 nspredicate 进行快速研究

ios - swift2 中的段错误 11

ios - React Native iOS 无法识别的字体系列 'Material Design Icons'

ios - iPhone拒绝了发布请求

ios - 自定义键盘文本完全替换 UISearchBar 中的文本而不是添加到它 [iOS]