更新UIButton边框颜色会延迟?
问题描述:
我们使用的是当连接到主视图控制器发送通知一些蓝牙通信,我们得到它的通知,:更新UIButton边框颜色会延迟?
- (void) receiveBLENotification:(NSNotification *) notification
{
if ([[notification name] isEqualToString:@"bluetooth"])
{
//here we log the title right on time but the next will happen only after a while
NSLog(@"!!!!!!!");
l1.layer.borderColor=[Globals sharedGlobals].mainColor.CGColor;
l2.layer.borderColor=[Globals sharedGlobals].mainColor.CGColor;
所以,出于某种原因,颜色改变,但我们得到的日志6秒后。
有没有办法强制它改变?
答
解决了这一点:
dispatch_async(dispatch_get_main_queue(), ^{
//here you update all required ui
});
是这6秒内冻结整个UI? – streem
这段时间我不能更新任何UI元素。 – Curnelious
这意味着主线程正忙,只有在完成后才会更新UI。当你收到你的通知时,你会执行任何沉重的操作吗? – streem