屏幕截图
Main.storyboard
ViewController.m
//
// ViewController.m
// 6A03.屏幕截图
//
// Created by huan on 16/1/30.
// Copyright © 2016年 huanxi. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
// 截取当前view 成为一张图片
//使用位图上下文
//1. 开启位图上下文
UIGraphicsBeginImageContext(self.view.bounds.size);
//2. 当前控制器的view画在位图上下文 render 渲染
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
//3.获得图片
UIImage *captureImg = UIGraphicsGetImageFromCurrentImageContext();
//4.结束位图编辑
UIGraphicsEndImageContext();
//save Image
NSData *imgData = UIImagePNGRepresentation(captureImg);
#warning 平时开发过程中,图片保存是沙盒
[imgData writeToFile:@"/Users/huan/Desktop/capture.png" atomically:YES];
}
@end