ViewController.m
import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UIImageView * imageV;
@end
@implementation ViewController
-
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
label.text = @"因为你是彭于晏呀";
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont fontWithName:nil size:50];[self.view addSubview:label];
self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(100, 50, 200, 250)];
self.imageV.image = [UIImage imageNamed:@"a.jpg"];
[self.view addSubview:_imageV];
//
}
//触摸且移动
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//获取图片的任意一点
UITouch * touch = touches.anyObject;
CGPoint contentPoint = [touch locationInView:self.imageV];
CGRect rect = CGRectMake(contentPoint.x, contentPoint.y, 10, 10);
//开启图片上下文
UIGraphicsBeginImageContextWithOptions(self.imageV.bounds.size, NO, 0);
// 获取花瓣上下文
CGContextRef ref = UIGraphicsGetCurrentContext();
//嫁给你imgeV的layer层映射到上下文中
[self.imageV.layer renderInContext:ref];
//清除划过的区域
CGContextClearRect(ref, rect);
//获取图片
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
//结束画板,图片消失
UIGraphicsEndPDFContext();
self.imageV.image = image;
}