In an iPad app, I have a bunch of UIImageViews inside a bigger UIView. Each UIImageView contains a thumbnail that is generated in a separate thread (so as not to freeze the application). After thumbnail has been successfully generated I call setNeedsDisplay
on main thread, however, it doesn't update the UIImageViews as the thumbs become available (I can see them in the log), rather it takes about 5 seconds and then displays all of them at once.
在iPad应用程序中,我在一个更大的UIView中有一堆UIImageViews。每个UIImageView都包含一个在单独的线程中生成的缩略图(以便不冻结应用程序)。成功生成缩略图后,我在主线程上调用setNeedsDisplay,但是,当拇指变得可用时,它不会更新UIImageViews(我可以在日志中看到它们),而是需要大约5秒,然后显示所有这些一旦。
here's what I am doing when a thumbnail has been created in a separate thread:
这是我在单独的线程中创建缩略图时所做的事情:
[self performSelectorOnMainThread:@selector(setNeedsDisplay)
withObject:nil
waitUntilDone:NO];
any ideas?
有任何想法吗?
3 个解决方案
#1
0
What's your main thread up to? If your application waits until all the thumbnails are available before redrawing, then it sounds like maybe you are inadvertently blocking on your main thread until your thumbnailing queue has emptied. How are you setting up the threads?
你的主要内容是什么?如果您的应用程序在重绘之前等待所有缩略图都可用,那么听起来好像您可能无意中阻塞了主线程,直到您的缩略图队列清空为止。你是如何设置线程的?
#2
0
The problem is that you can't tell cocoa that it have to redraw "now". With setNeedsDisplay
you can onely order a redraw, because drawing is ra rather expensive procces.
问题是你不能告诉可可它必须“现在”重绘。使用setNeedsDisplay,您可以单独订购重绘,因为绘图是相当昂贵的过程。
setNeedsDisplay
You can use this method or the setNeedsDisplayInRect: to notify the system that your view’s contents need to be redrawn. This method makes a note of the request and returns immediately. The view is not actually redrawn until the next drawing cycle, at which point all invalidated views are updated.
您可以使用此方法或setNeedsDisplayInRect:来通知系统您的视图内容需要重绘。此方法记录请求并立即返回。在下一个绘制周期之前,视图实际上不会重绘,此时所有无效视图都会更新。
Mybe its a better and more performant solution to wait for all generated thumbnials?!
Mybe是一个更好,更高效的解决方案,等待所有生成的缩略图?!
#3
0
I would use NSNotification. Send a notification from your thread loading the images when an image is ready. Your view controller can observe these notifications and update the view as they arrive.
我会使用NSNotification。在图像准备好时,从线程发送加载图像的通知。您的视图控制器可以观察这些通知并在视图到达时更新视图。
#1
0
What's your main thread up to? If your application waits until all the thumbnails are available before redrawing, then it sounds like maybe you are inadvertently blocking on your main thread until your thumbnailing queue has emptied. How are you setting up the threads?
你的主要内容是什么?如果您的应用程序在重绘之前等待所有缩略图都可用,那么听起来好像您可能无意中阻塞了主线程,直到您的缩略图队列清空为止。你是如何设置线程的?
#2
0
The problem is that you can't tell cocoa that it have to redraw "now". With setNeedsDisplay
you can onely order a redraw, because drawing is ra rather expensive procces.
问题是你不能告诉可可它必须“现在”重绘。使用setNeedsDisplay,您可以单独订购重绘,因为绘图是相当昂贵的过程。
setNeedsDisplay
You can use this method or the setNeedsDisplayInRect: to notify the system that your view’s contents need to be redrawn. This method makes a note of the request and returns immediately. The view is not actually redrawn until the next drawing cycle, at which point all invalidated views are updated.
您可以使用此方法或setNeedsDisplayInRect:来通知系统您的视图内容需要重绘。此方法记录请求并立即返回。在下一个绘制周期之前,视图实际上不会重绘,此时所有无效视图都会更新。
Mybe its a better and more performant solution to wait for all generated thumbnials?!
Mybe是一个更好,更高效的解决方案,等待所有生成的缩略图?!
#3
0
I would use NSNotification. Send a notification from your thread loading the images when an image is ready. Your view controller can observe these notifications and update the view as they arrive.
我会使用NSNotification。在图像准备好时,从线程发送加载图像的通知。您的视图控制器可以观察这些通知并在视图到达时更新视图。