2
我正在將CIFilter
應用到UIImage
,但它正在減慢滾動我的UITableView
。我能做什麼?CIFilter減慢滾動
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"tweetCell";
TweetCell *cell = (TweetCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TweetCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.tweet.text = _tweets[indexPath.row][@"text"];
NSDictionary *tweetData = _tweets[indexPath.row];
NSString *profilePhotoURL = _profilePhotos[tweetData[@"username"]];
UIImage *bgPicture = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:profilePhotoURL]]];
dispatch_async(dispatch_get_main_queue(), ^(void){
CIFilter *gaussianBlurFilter = [CIFilter filterWithName:@"CIGaussianBlur"];
[gaussianBlurFilter setDefaults];
[gaussianBlurFilter setValue:[CIImage imageWithCGImage:[bgPicture CGImage]] forKey:kCIInputImageKey];
[gaussianBlurFilter setValue:@0.7 forKey:kCIInputRadiusKey];
CIImage *outputImage = [gaussianBlurFilter outputImage];
CIContext *context = [CIContext contextWithOptions:nil];
CGRect rect = [outputImage extent];
rect.origin.x += (rect.size.width - bgPicture.size.width)/2;
rect.origin.y += (rect.size.height - bgPicture.size.height)/2;
rect.size = bgPicture.size;
CGImageRef cgimg = [context createCGImage:outputImage fromRect:rect];
UIImage *image = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);
cell.bgP.image = image;
});
return cell;
}
我的意思是我已經添加了使得滾動更好一點的調度片。但是,當我在UITableView
上滾動速度非常快時,圖像和圖像過濾器會被加載,但在滾動時會經常出現凹凸或鋸齒狀。
謝謝,它使它好一點,但仍然有明顯的滯後。 –