Getting a screenshot of a UIScrollView, including offscreen parts

前端 未结 12 2124
遥遥无期
遥遥无期 2020-11-22 17:31

I have a UIScrollView decendent that implements a takeScreenshot method that looks like this:

-(void)takeScreenshot {  
  CGRect contextRect  =          


        
12条回答
  •  名媛妹妹
    2020-11-22 18:06

    I have found below code and its working for me. try this ..

    extension UIView {
    func capture() -> UIImage {
        UIGraphicsBeginImageContextWithOptions(bounds.size, false, UIScreen.main.scale)
        drawHierarchy(in: self.bounds, afterScreenUpdates: true)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }}
    

提交回复
热议问题