我在我的项目中有一个错误(我已经第二次遇到),我只需在UIViewController视图的顶部添加一个视图。什么都不突出,像这样:UI故障,尽管在主线程上运行UI操作的事实
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.displayEmailNotificationsIfNeeded()
}
的错误是,由于某种原因,自动布局不正确地工作,并在顶部不加它,而是围绕60pt比需要的低。我怀疑〜60pt来自手动顶部约束调整,包括导航栏和状态栏,但这并不重要。
的事实是,如果我在主队列明确运行的方法,像这样的问题就会消失:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
print("is main thread: ", NSThread.isMainThread())
dispatch_async(dispatch_get_main_queue(), {() -> Void in
print("is main thread inside block: ", NSThread.isMainThread())
self.displayEmailNotificationsIfNeeded()
})
}
打印语句返回true
两种情况。这不是很糟糕,但出于好奇,我想了解是什么原因造成的。有没有办法调试这种情况,并理解为什么在主线程上明确执行操作修复了一些UI故障?