TTThumbsViewController 滚动时显示图像

发布于 2024-12-19 08:02:34 字数 927 浏览 0 评论 0原文

我正在扩展 TTThumbsViewController 来显示来自外部源的照片。一切正常,但我想更改控制器的一种行为:我想在用户仍在滚动时而不是仅在用户完成滚动时在 TTThumbsViewController 中显示/加载图像。

我在 TTTableViewDelegate.m 中看到,滚动开始时请求被挂起,我尝试将其设置为“否”,但它似乎只获取图像,而在完成加载时并未实际显示它们。

//TTTableViewDelegate.m
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  [TTURLRequestQueue mainQueue].suspended = YES;
  ...
}

此外,我连接了开始和结束拖动委托调用,尝试每秒左右刷新视图,希望显示缩略图,我尝试过调用 invalidateViewreload 以及主线程上的更多内容,但似乎都不起作用(invalidateModel 不适合我的目的)。

有人能指出我正确的方向吗?

预先感谢

Edit1:如果我在使用 [TTURLRequestQueue mainQueue].suspended = NO; 时滚动,状态栏中会有一个加载程序,但它实际上并没有获取图像,用wireshark确认。

Edit2:经过更多调试后,我发现请求是以编程方式发送的,但只有在完成滚动后才会收到响应,因此看来 NSURLConnection 的异步委托方法是在滚动 scrollView 时不会触发,但我已经设法在另一个具有 tableView 的视图控制器中执行类似的代码(工作),而无需使用 Three20 lib。

I'm extending TTThumbsViewController to display photos from external source. Everything works fine but I'd like to change one behaviour of the controller: I'd like to display/load images in TTThumbsViewController while the user is still scrolling and not only when the user finishes scrolling.

I saw that in TTTableViewDelegate.m the requests are being suspended when scrolling starts and I've tried setting it no NO but it only seems to fetch the images and not actually displaying them when they finish loading.

//TTTableViewDelegate.m
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  [TTURLRequestQueue mainQueue].suspended = YES;
  ...
}

In addition I hooked to the begin and end dragging delegate calls to try and refresh the view every second or so with hopes of displaying the thumbnails, I've tried calling invalidateView, reload and a couple more on the main thread but none seemed to work (invalidateModel doesn't suit my purposes here).

Could anyone point me in the right direction?

Thanks in advance

Edit1: there is a loader in status bar if I scroll when I use [TTURLRequestQueue mainQueue].suspended = NO; but it doesn't actually fetch the images, confirmed with wireshark.

Edit2: after a bit more debugging I found that the request is sent programatically but the response is only received after we finish scrolling, so it seems the asynchronous delegate methods of NSURLConnection are not firing while a scrollView is being scrolled, but I've managed to do similar code (working) in another view controller with a tableView without using three20 lib.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自由如风 2024-12-26 08:02:34

在谷歌搜索大量线程和论坛后,我终于实现了我想要的行为,尽管我更改了 Three20 代码而不是在一部分中扩展它:在我的thumbsViewController中我实现了以下委托,允许在滚动时发出请求:

-(void)didBeginDragging {
    [super didBeginDragging];
    [TTURLRequestQueue mainQueue].suspended = NO;
}

现在为了解决滚动时未处理连接的问题,我发现当 UIScrollView 滚动时 NSURLRequest 不会触发 有用并且在 TTRequestLoader.m 我更改了以下内容:

//TTRequestLoader.m
- (void)connectToURL:(NSURL*)URL {
    ...
    //To allow requests while scrolling we must schedule the conenction in other run loop
    //_connection = [[NSURLConnection alloc] initWithRequest:URLRequest delegate:self];
    //code above was replaced by the one below
    _connection = [[NSURLConnection alloc] initWithRequest:URLRequest delegate:self startImmediately:NO];
    [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    [_connection start];
}

After googling around numerous threads and forums I finally achieved the behaviour I wanted, although I changed three20 code instead of extending it in one part: in my thumbsViewController I implemented the following delegate allowing requests to be made while scrolling:

-(void)didBeginDragging {
    [super didBeginDragging];
    [TTURLRequestQueue mainQueue].suspended = NO;
}

Now to solve the problem of the connections not being processed while scrolling I found NSURLRequest won't fire while UIScrollView is scrolling useful and in TTRequestLoader.m I changed the following:

//TTRequestLoader.m
- (void)connectToURL:(NSURL*)URL {
    ...
    //To allow requests while scrolling we must schedule the conenction in other run loop
    //_connection = [[NSURLConnection alloc] initWithRequest:URLRequest delegate:self];
    //code above was replaced by the one below
    _connection = [[NSURLConnection alloc] initWithRequest:URLRequest delegate:self startImmediately:NO];
    [_connection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
    [_connection start];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文