Screenshot Only Part of Screen - Swift

前端 未结 4 1098
时光说笑
时光说笑 2021-02-07 03:43

I\'m using this Swift code to take a screenshot of my app:

UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size, false, 0);
self.view.drawVi         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-07 04:04

    for taking a snapshot selecting by area of another UIView

    // viewObject: UIView linked from storyboard
    var bounds= CGRect(x: -viewObject.frame.minX,y: -viewObject.frame.minY,width: view.bounds.size.width,height: view.bounds.size.height)
    
    UIGraphicsBeginImageContext(viewObject.frame.size)
            view.drawHierarchy(in: bounds, afterScreenUpdates: true)
            let outputImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
            UIGraphicsEndImageContext()
    

提交回复
热议问题