我正在开发一个项目,我使用Avplayer的自定义控件播放视频。我希望允许用户绘制视频,并使用下面的代码截取自定义播放器的屏幕截图,它在模拟器中运行良好,而在物理设备中即使在更改afterScreenUpdates后返回黑屏:(真/假)
let window = UIApplication.sharedApplication().delegate!.window!!
//capture the entire window into an image
UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, UIScreen.mainScreen().scale)
window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: true)
let windowImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
//now position the image x/y away from the top-left corner to get the portion we want
UIGraphicsBeginImageContext(imageView.frame.size)
windowImage.drawAtPoint(CGPoint(x: -imageView.frame.origin.x, y: -imageView.frame.origin.y))
let croppedImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
//embed image in an imageView, supports transforms.
let resultImageView = UIImageView(image: croppedImage)
UIImageWriteToSavedPhotosAlbum(croppedImage, nil, nil, nil)
任何建议都会有所帮助