最近做直播,有个截屏的需求,按照网上的方法截屏后画面没有图像!找了好久终于找到了解决办法!
写个extension,然后我是用 ViewController.view.getViewShot() 就OK了!!
extension UIView {
func getViewShot() -> UIImage? {
UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, UIScreen.main.scale)
self.drawHierarchy(in: self.bounds, afterScreenUpdates: false)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}