在我的collectionView中,我有一幅具有白色背景的图像,我使用KCG混合模式制作了另一幅图像,并将其添加为覆盖以使背景变为灰色。问题是,当我滚动查看新图像或滚动浏览以查看旧图像时,图像会重置为原始图像。
我相信这是由于dequeueReusableCell
造成的:
-(UICollectionViewCell *)collectionView:(UICollectionView
*)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Product *product = [self.products content][indexPath.row];
ProductCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kGENERIC_COLLECTION_CELL_ID forIndexPath:indexPath];
//set image
NSString *imageUrlString = [NSString stringWithFormat:@"%@%@", [product image_thumb_path], [product image_thumb]]; //create url using path & image
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:imageUrlString]
placeholderImage:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
if (cacheType != SDImageCacheTypeMemory)
{
// cell.imageView.alpha = 0.0;
double val = ((double)arc4random()/ARC4RANDOM_MAX)*0.8;
[UIView animateWithDuration:0.2 delay:val options:UIViewAnimationOptionCurveEaseInOut animations:^{
UIImage *backgroundImage = [UIImage imageNamed:@"grey.jpeg"];
CGFloat width = 100;
CGFloat height = 100;
CGSize size = CGSizeMake(width, height);
UIGraphicsBeginImageContext(size);
CGRect areaSize = CGRectMake(0, 0, size.width, size.height);
[backgroundImage drawInRect:areaSize];
[image drawInRect:areaSize blendMode:kCGBlendModeMultiply alpha:2.8];
UIImage *mainImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = mainImage;
// cell.imageView.image = [cell.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
// cell.imageView.tintColor = UIColor.grayColor;
// cell.imageView.image = [cell.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
} completion:nil];
}
}];
}
什么是避免遇到此问题的最佳方法?