ios - 以编程方式截图并在 Swift 中模糊

标签 ios xcode swift screenshot blur

我想以编程方式从我的应用程序截取屏幕截图并且代码工作正常但我有一个具有模糊效果的 UIVisualEffectView 并且屏幕截图给了我没有模糊的图像! 我怎样才能使屏幕截图也变得模糊?

UIGraphicsBeginImageContextWithOptions(fullView.bounds.size, true, 1)
self.fullView.layer.renderInContext(UIGraphicsGetCurrentContext())
var viewImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil)

最佳答案

要在以编程方式拍摄屏幕图像时保留 UIVisualEffectView 模糊,您必须拍摄整个屏幕的图像。

这是 Apple 提供的更技术性的定义:

Many effects require support from the window that hosts the UIVisualEffectView. Attempting to take a snapshot of only the UIVisualEffectView will result in a snapshot that does not contain the effect. To take a snapshot of a view hierarchy that contains a UIVisualEffectView, you must take a snapshot of the entire UIWindow or UIScreen that contains it. - Apple Documentation

关于ios - 以编程方式截图并在 Swift 中模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27118391/

相关文章:

ios - 错误 ("' ( )' is not identical to ' UInt 8'") 使用 Swift 中的写入函数将 NSData 字节写入 NSOutputStream

objective-c - 手势和响应链

ios - 快速引用子类中的 Outlet

ios - 如何将模型类字典中的值存储在 Array/NSMutableArray 中?

ios - 关闭消息 View Controller

iOS Storyboard为什么有些元素没有出现在模拟器中?

ios - 我们可以在 Xcode 7.3 上安装 iOS 10 模拟器吗

ios - 加载本地存储的 mp3 音频文件时出现 UIWebView 问题

ios - 如何将子图层居中放置在另一图层上?

swift - 解析安装deleteInBackground()