Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我添加一个观察者来观察 UILabel 的“突出显示”属性,我可以在观察回调块中更改另一个 UIView 吗?即:我能保证这个回调块总是在主线程上执行吗?
谢谢!
observeValueForKeyPath:...您将在更改您正在观察的属性的线程上收到消息。
observeValueForKeyPath:...
UIKit 仅支持在主线程上更改视图的属性。只要您遵循该规则,您只会在主线程上收到通知。
如果您需要highlighted从另一个线程更改标签的属性,您应该分派到主线程来执行此操作。例如,您可以从任何线程安全地执行此操作:
highlighted
dispatch_async(dispatch_get_main_queue(), ^{ myLabel.highlighted = YES; });