Screenshot Only Part of Screen - Swift

前端 未结 4 1089
时光说笑
时光说笑 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 03:49

    I think this is the best Answer to take a shot of part of the screen:

    func screenShot() {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(self.frame.size.width*0.99,self.frame.size.height*0.70), false, 0)
        var image:UIImage = UIGraphicsGetImageFromCurrentImageContext();
        self.view?.drawViewHierarchyInRect(CGRectMake(-01, -01, self.frame.size.width, self.frame.size.height), afterScreenUpdates: true)
        var screenShot  = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
    }
    

提交回复
热议问题