截屏

//开启一个和图片相关的图形上下文
    UIGraphicsBeginImageContextWithOptions(self.shotView.bounds.size, NO, 0.0);
    
    //获取刚刚开启的上下文
    CGContextRef ref = UIGraphicsGetCurrentContext();
    
    //进行截图 把当前控制器view的显示效果绘制到图形上下文中 / 截取shotView
    [self.shotView.layer renderInContext:ref];
    
    //从上下文中获取图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    //关闭图形上下文
    UIGraphicsEndImageContext();
    
    self.imgView.image = image;
1628174-ca05fe1406c2ed81.png
Simulator Screen Shot - iPhone 8 Plus - 2019-01-23 at 15.02.16.png

link

猜你喜欢

转载自blog.csdn.net/weixin_33788244/article/details/87516554