問題描述
我有一個(gè)問題,我試圖在用戶在 UIScrollView 周圍移動(dòng)時(shí)在后臺(tái)加載聲音文件...問題是我正在使用 NSURLRequest 所以我可以在后臺(tái)加載,但即使這樣它也拒絕實(shí)際加載直到 UIScrollView 停止?jié)L動(dòng).:(
I have a problem in that I am trying to background load a sound file while the user moves around a UIScrollView... The problem is that I am using NSURLRequest so I can load in the background, but even then it refuses to actually load until the UIScrollView has stopped scrolling. :(
對(duì)此我有什么辦法嗎?
謝謝!
推薦答案
NSURLRequest
只管理請(qǐng)求,不管理實(shí)際連接.
The NSURLRequest
only manages the request, not the actual connection.
滾動(dòng)等觸摸事件會(huì)將運(yùn)行循環(huán)置于NSEventTrackingRunLoopMode
.默認(rèn)情況下,NSURLConnection
被調(diào)度為僅 在 NSDefaultRunLoopMode
中執(zhí)行.所以在 NSEventTrackingRunLoopMode
中,NSDefaultRunLoopMode
被阻塞了.
Touch events such as scrolling will place the run loop into NSEventTrackingRunLoopMode
. By default, an NSURLConnection
is scheduled to only execute in NSDefaultRunLoopMode
. So while in NSEventTrackingRunLoopMode
, NSDefaultRunLoopMode
is blocked.
好消息是您可以為 NSURLConnection
安排其他模式,例如 NSRunLoopCommonModes
.
Good news is that you can schedule additional modes for an NSURLConnection
, such as NSRunLoopCommonModes
.
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
[connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
[connection start];
這篇關(guān)于NSURLRequest 在 UIScrollView 滾動(dòng)時(shí)不會(huì)觸發(fā)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!