我相信NDA已關閉,所以我可以問這個問題。我有一個UIView子類:模糊屏幕與iOS 7的快照API
BlurView *blurredView = ((BlurView *)[self.view snapshotViewAfterScreenUpdates:NO]);
blurredView.frame = self.view.frame;
[self.view addSubview:blurredView];
到目前爲止,它在捕獲屏幕上的工作,但現在我想模糊該視圖。我究竟如何去做這件事?從我讀過的內容中,我需要捕獲視圖(上下文?!)的當前內容並將其轉換爲CIImage(不是?),然後將CIGaussianBlur應用於它並在視圖上繪製。
我到底該怎麼做?
P.S.該視圖不是動畫,所以它應該是明智的性能。
編輯:這是我到目前爲止。問題是我無法捕捉快照到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;
}
WWDC2013示例代碼中有一個UIImageView類別。 –
我檢查了它,但它使用資源中的圖像作爲源,而我需要使用快照。我無法弄清楚。 –