我相信NDA已经解除,所以我可以问这个问题。我有一个UIView子类:
BlurView *blurredView = ((BlurView *)[self.view snapshotViewAfterScreenUpdates:NO]);
blurredView.frame = self.view.frame;
[self.view addSubview:blurredView];
迄今为止,它在捕获屏幕方面表现良好,但现在我想模糊该视图。我应该如何操作?从我所了解的,我需要捕获视图(上下文?!)的当前内容并将其转换为CIImage(不是吗?),然后对其应用CIGaussianBlur,并将其绘制回视图中。
我应该怎么做?
附注:该视图没有动画,因此在性能方面应该没问题。
编辑:这是我到目前为止所拥有的。问题是我无法将快照捕获到UIImage中,我得到的是黑屏。但是如果我直接将视图添加为子视图,我可以看到快照在那里。
// Snapshot
UIView *view = [self.view snapshotViewAfterScreenUpdates:NO];
// Convert to UIImage
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Apply the UIImage to a UIImageView
BlurView *blurredView = [[BlurView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
[self.view addSubview:blurredView];
blurredView.imageView.image = img;
// Black screen -.-
BlurView.m:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.imageView = [[UIImageView alloc] init];
self.imageView.frame = CGRectMake(20, 20, 200, 200);
[self addSubview:self.imageView];
}
return self;
}