2015-05-14 87 views
3

我以編程方式模糊了我的視圖並添加了帶有屏幕截圖的共享擴展,但屏幕截圖不會模糊我在圖像中的視圖。在迅速UIBlurEffect在試圖以編程方式快速截取屏幕截圖時不起作用

代碼所有編程模糊

let blurEffect = UIBlurEffect(style:.Dark) 
let blurView = UIVisualEffectView(effect: blurEffect) 
blurView.frame = imageView2.frame 
self.view.addSubview(blurView) 

代碼截圖

UIGraphicsBeginImageContext(view.frame.size) 
view.layer.renderInContext(UIGraphicsGetCurrentContext()) 
let image = UIGraphicsGetImageFromCurrentImageContext() 
UIGraphicsEndImageContext() 

感謝

回答

7

嘗試服用SCRE enshot這樣:

捕獲的UIVisualEffectView 許多影響快照需要從託管UIVisualEffectView窗玻璃支架:

UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, 0) 
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true) 
let image = UIGraphicsGetImageFromCurrentImageContext() 
UIGraphicsEndImageContext() 
+0

非常感謝!它工作完美 –

+0

雖然你能幫我,狀態欄丟失 –

+0

更改'view.drawViewHierarchy ...'到'view.window?.drawViewHierarchy ...' – pteofil

2

我剛剛發現蘋果實際上已經就如何採取UIVisualEffectView的快照記錄。嘗試僅拍攝UIVisualEffectView的快照將導致不包含該效果的快照。 要獲取包含UIVisualEffectView的視圖層次結構的快照,必須拍攝包含它的整個UIWindow或UIScreen的快照。

謝謝!