Swift - 截屏
func screenSnapshot(save save: Bool) -> UIImage? {
guard let window = UIApplication.sharedApplication().keyWindow else { return nil }
// 用下面这行而不是UIGraphicsBeginImageContext(),因为前者支持Retina
UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, 0.0)
window.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
if save { UIImageWriteToSavedPhotosAlbum(image, self, nil, nil) }
return image
}
本文标题:Swift - 截屏
本文链接:https://www.haomeiwen.com/subject/cfhokttx.html
网友评论