NSURLRequest 在 UIScrollView 滚动时不会触发

NSURLRequest won#39;t fire while UIScrollView is scrolling(NSURLRequest 在 UIScrollView 滚动时不会触发)
本文介绍了NSURLRequest 在 UIScrollView 滚动时不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个问题,我试图在用户在 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];

这篇关于NSURLRequest 在 UIScrollView 滚动时不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
Handling scroll views with (custom, interactive) view controller presentation and dismissal(使用(自定义、交互式)视图控制器呈现和解除处理滚动视图)