UICollectionView 滚动不流畅.为什么? [英] UICollectionView scrolling is not smooth. Why?

查看:43
本文介绍了UICollectionView 滚动不流畅.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的 UICollecionView 滚动不流畅?

Why my UICollecionView's scrolling is not smooth?

这是代码:

static NSString *CellIdentifier = @"cellRecipe";

// Configure the cell...

[cell setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:@"bgRecipeCell.png"]]];

cell.image.layer.masksToBounds = YES;
cell.image.layer.cornerRadius = 8.0f;
cell.image.layer.borderColor = [UIColor blackColor].CGColor;
cell.image.layer.borderWidth = 1.0f;

Recipes *recipe = [recipesArray_ objectAtIndex:indexPath.item];

//checking for purchase
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSObject *object = [prefs objectForKey:@"com.__.__.recipefree"];

if ([recipe.isPaid integerValue] == 0) {
    [cell.freeImage setHidden:NO];
}
else [cell.freeImage setHidden:YES];

if ([object isEqual:[NSNumber numberWithInt:1]]) {
    [cell.freeImage setHidden:YES];
}

if ([recipe.isFavorite integerValue] == 0) {
    [cell.favImage setImage:[UIImage imageNamed:@"toFavorite.png"] ];
}
else [cell.favImage setImage: [UIImage imageNamed:@"toFavorite_.png"]];

[cell.recipeName setText: recipe.name];
[cell.image setImage:recipe.thumbImage];

MainTabController *mainTabController = [[MainTabController alloc] init];
int difficulty = [recipe.difficulty intValue];
//this is the function which return an image for difficulty level from 1 to 5
[cell.difficultyImage setImage: [mainTabController imageForRating:difficulty]];

return cell;

推荐答案

这是一个老问题,但如果有人仍在寻找答案,那么一个简短的技巧将是,在 cellForItemAtIndexPath 中,首先 dequeue 你的 collectionView 单元格:

It's an old question, but in case if anyone still looking for answer then a short trick will be, in cellForItemAtIndexPath, first dequeue your collectionView cell :

CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

然后添加以下行:

cell.layer.shouldRasterize = YES;cell.layer.rasterizationScale = [UIScreen mainScreen].scale;

这篇关于UICollectionView 滚动不流畅.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆