Swift - 截屏

96
Hesse_Huang
2016.03.03 20:50* 字数 0
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开发小记
Web note ad 1