我有這樣的代碼等待裝載任務,呈現出activityIndicator視圖什麼是UI動畫和主要runloop之間的關係
if (isLoading) {
self.tipView = [[BBTipsView alloc] initWithMessage:@"loading..." showLoading:YES parentView:self.view autoClose:NO];
self.tipView.needsMask = YES;
[self.tipView show];
while (isLoading) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
[self.tipView close];
}
加載視圖將動畫,直到isLoading成爲false.here是我的問題: 在主線程中運行runloop會阻塞主線程,直到發生源事件或定時器觸發爲止。但是爲什麼在主循環沒有返回時加載視圖保持動畫?
-----通過bupo ----
編輯我發現,當定時觸發runloop將不會返回。這將有意義的動畫刷新ui由CADisplayLink定時器火災。
Note that from the perspective of NSRunloop, NSTimer objects are not "input"—they are a special type, and one of the things that means is that they do not cause the run loop to return when they fire.
現代動畫很少有做的RunLoop。它們依賴稱爲顯示鏈接的定時器基元,後者可以在後臺線程上運行,以確保與顯示器相連的刷新率,而不是CPU。 – CodaFi
你的意思是UI刷新沒有在主線程上運行? –
你得到的顯示回調只是主線程。計時器是在後臺運行的。 – CodaFi