当UIScrollView滚动时,NSURLRequest不会触发 [英] NSURLRequest won't fire while UIScrollView is scrolling
问题描述
我有一个问题,我试图在用户移动UIScrollView时后台加载声音文件...问题是我使用NSURLRequest所以我可以在后台加载,但即使这样它也拒绝实际加载直到UIScrollView停止滚动。 :(
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. :(
我能做些什么吗?
谢谢!
推荐答案
NSURLRequest
仅管理请求,而不是实际连接。
The NSURLRequest
only manages the request, not the actual connection.
触摸事件(如滚动)会将运行循环放入 NSEventTrackingRunLoopMode
。默认情况下, NSURLConnection
计划仅在 NSDefaultRunLoopMode
中执行。所以在 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];
这篇关于当UIScrollView滚动时,NSURLRequest不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!