截屏实现

有的时候需要将程序的页面进行截屏处理,怎么实现呢?其实很简单的,代码如下:

#import <QuartzCore/QuartzCore.h>

//注意要先添加QuartzCore.framework库

-(void) screenShot
{
    UIGraphicsBeginImageContext(self.bounds.size);
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image= UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    NSLog(@"image:%@",image);
    UIImageView *imaView = [[UIImageView alloc] initWithImage:image];
    imaView.frame = CGRectMake(0, 700, 500, 500);
    [self addSubview:imaView];
    [imaView release];
    UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}

那么上面的截屏能够用在那些地方呢?

(1)在聊天的时候,将本页面以图片的形式发送给对方

(2)点击A页面上的一个按钮,出现弹框,弹框是push或者模态过去的,默认没有动画效果,但是弹框的背景还是A页面。

其他地方有可能也会用到该技术。

原文地址:https://www.cnblogs.com/benpaobadaniu/p/4893114.html