我在集合視圖中顯示了多張專輯圖像。 用於在單元格方法中顯示圖像cellForItemAtIndexPath包含如下代碼。如何使UICollectionView滾動更快
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
AlbumImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AlbumImageCell" forIndexPath:indexPath];
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"AlbumImageCell" owner:self options:nil] objectAtIndex:0];
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *inputPath = [[self.arrTbl_Album_Image objectAtIndex:indexPath.row]objectAtIndex:2 ];
NSString *imageEx=[inputPath pathExtension];
NSString *imageName=[[inputPath lastPathComponent]stringByDeletingPathExtension];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@",imageName,imageEx]];
[cell.albumImage setImage:[UIImage imageWithContentsOfFile:fullPath]];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData *data= [NSData dataWithContentsOfFile:fullPath];
UIImage *theImage=[UIImage imageWithData:data];
dispatch_async(dispatch_get_main_queue(), ^{
cell.albumImage.image=theImage;
});
});
}
問題是UICollection視圖滾動緩慢的工作時,我滾動,所以我需要做的滾動faster.I應用一些解決方案,但問題仍然沒有解決。 請幫我解決這個問題。
爲什麼不把圖像放在'xcassets'而不是使用'Documents文件夾'?它提高了加載速度和滾動 –
@LucaD你可以建議我一些小例子,我如何使用Xcassets而不是文檔目錄? –