截图

来源:互联网 发布:vscode使用技巧 编辑:程序博客网 时间:2024/04/29 02:41
- (UIImage *)screenshot:(UIDeviceOrientation)orientation isOpaque:(BOOL)isOpaque usePresentationLayer:(BOOL)usePresentationLayer
 {
     CGSize size;
 
     if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
         size = CGSizeMake(self.view.frame.size.width, self.frame.size.height);
     } else {
         size = CGSizeMake(self.view.frame.size.height, self.frame.size.width);
     }
 
     UIGraphicsBeginImageContextWithOptions(size, isOpaque, 0.0);
 
     if (usePresentationLayer) {
         [self.view.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
     } else {
         [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
     }
 
     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 
     UIGraphicsEndImageContext();
 
     return image;
 }
 
//使用方法:

UIImage *image = [self.view screenshot:UIDeviceOrientationPortrait   isOpaque:YES usePresentationLayer:YES];  

//isopaque 是否不透明 

//usePresentationLayer 使用外层的意思吗没验证过

0 0
原创粉丝点击