ios截屏后发现图片是空白问题

ios截图代码:

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);

    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

    return img;


发现截图后图片是空白的,只要添加一句

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()]; //将需要截图的layer渲染到context上
   UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    return img;

你可能感兴趣的:(ios)