UIScrollView 滚动时 NSURLRequest 不会触发
我有一个问题,当用户在 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. :(
Is there anything I can do about this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSURLRequest
仅管理请求,而不管理实际连接。滚动等触摸事件会将运行循环置于 NSEventTrackingRunLoopMode 中。默认情况下,
NSURLConnection
被安排为仅在NSDefaultRunLoopMode
下执行。因此,在NSEventTrackingRunLoopMode
中,NSDefaultRunLoopMode
被阻止。好消息是,您可以为
NSURLConnection
安排其他模式,例如NSRunLoopCommonModes
。The
NSURLRequest
only manages the request, not the actual connection.Touch events such as scrolling will place the run loop into
NSEventTrackingRunLoopMode
. By default, anNSURLConnection
is scheduled to only execute inNSDefaultRunLoopMode
. So while inNSEventTrackingRunLoopMode
,NSDefaultRunLoopMode
is blocked.Good news is that you can schedule additional modes for an
NSURLConnection
, such asNSRunLoopCommonModes
.我已经找到了一个困难的方法,如果你调用 startImmediately:YES 或省略这个参数,第二行是完全没有用的。因此,请务必遵循@tidwall 提供的确切模式。
这也是一个简单的例子:
I've figured out the hard way that if you call startImmediately:YES or ommit this parameter second line is completely useless. So be sure to follow the exact pattern provided by @tidwall.
Here's also a swift example: