私はUIImageView
私の習慣を手に入れましたUITableViewCell
。含まれている画像はぼやけている必要があります。私は知っていますがUIVisualEffectsView
、まず第一にこれは以前は利用できずiOS8
、第二に私のユースケースではぼかしが少し重いです。
それが私がこの解決策を思いついた理由です:
サンプルcellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"showCell";
DEShowCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
[tableView registerNib:[UINib nibWithNibName:@"DEShowCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:cellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
}
[cell setBackgroundImageWithBlur:[UIImage imageNamed:@"sampleBanner"]];
return cell;
}
私のカスタムセル:
-(void)setBackgroundImageWithBlur:(UIImage *)image {
[self.backgroundImageView setImage:[self blurWithCoreImage:image]];
}
- (UIImage *)blurWithCoreImage:(UIImage *)sourceImage
{
CIImage *inputImage = [CIImage imageWithCGImage:sourceImage.CGImage];
// Apply Affine-Clamp filter to stretch the image so that it does not
// look shrunken when gaussian blur is applied
CGAffineTransform transform = CGAffineTransformIdentity;
CIFilter *clampFilter = [CIFilter filterWithName:@"CIAffineClamp"];
[clampFilter setValue:inputImage forKey:@"inputImage"];
[clampFilter setValue:[NSValue valueWithBytes:&transform objCType:@encode(CGAffineTransform)] forKey:@"inputTransform"];
// Apply gaussian blur filter with radius of 30
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:clampFilter.outputImage forKey: @"inputImage"];
[gaussianBlurFilter setValue:@10 forKey:@"inputRadius"];
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:gaussianBlurFilter.outputImage fromRect:[inputImage extent]];
// Set up output context.
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef outputContext = UIGraphicsGetCurrentContext();
// Invert image coordinates
CGContextScaleCTM(outputContext, 1.0, -1.0);
CGContextTranslateCTM(outputContext, 0, -self.frame.size.height);
// Draw base image.
CGContextDrawImage(outputContext, self.frame, cgImage);
// Apply white tint
CGContextSaveGState(outputContext);
CGContextSetFillColorWithColor(outputContext, [UIColor colorWithWhite:1 alpha:0.2].CGColor);
CGContextFillRect(outputContext, self.frame);
CGContextRestoreGState(outputContext);
// Output image is ready.
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outputImage;
}
残念ながら、これをスクロールしようとすると、パフォーマンスに大きな問題が発生しますUITableView
。
だから私は私に回避策を尋ねましたか?いくつかのライブラリを使用して、ぼかすのGPUImage
が速くなると思いますが、これが大きな違いを生むかどうかはわかりません。
UITableView
約含まれています20-60行、私は思います。
キャッシングや他の何かのような他のアイデアはありますか?
dynamic = NOに設定してFXBlurViewを使用します。それはまともなパフォーマンスを持っています。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加