2010-07-21 65 views
1

我正在写为iPad的读者,显示在一个UIScrollView的UIScrollView动画laggy

每个图像加载时需要这种耐心(滚动时)后台线程图像(1024x1322最大)(总有3张已加载图片在最大)。

我的问题是:当数据被加载我更新的UIImageView,在我的后台线程这样的:

image= [[UIImage alloc] initWithContentsOfFile: file]; 
[content setImage:image] 

这似乎“锁”在主线程,使UIScrollView的动画不流畅在所有。

感谢您事先的任何线索

+0

您是否解决了这个问题?在图像密集型应用程序中将图像缓存到磁盘时遇到类似问题。仍然不知道一个好的解决方案。 http://stackoverflow.com/questions/3756863/scroll-view-and-table-view-performance-when-loading-images-from-disk – pmc255 2010-09-23 22:17:33

+0

而且你不应该在主线程以外的线程中访问UIKit - http ://developer.apple.com/library/ios/#documentation/uikit/reference/UIKit_Framework/Introduction/Introduction.html - “UIKit类只能从应用程序的主线程中使用” – 2011-04-24 06:55:05

回答

0

做这样的事情在你的后台线程,而不是使用UIImage的

CGDataProviderRef dataProvider = CGDataProviderCreateWithFilename("file.png"); 
CGImageRef image = CGImageCreateWithPNGDataProvider(dataProvider, NULL, NO, kCGRenderingIntentDefault); 

传回的图像裁判你的主线程,然后创建一个UIImage的[ UIImage的imageWithCGImage:图片]

希望这有助于

2

你应该从未 SE t来自后台线程的图像视图(或任何UI组件的任何属性)的图像。 UIKit而不是线程安全。您需要将图像传递到主线程,使用GCD或performSelectorOnMainThread:withObject:waitUntilDone: