本例子类似于微信头像上传前对上传图片的剪裁功能,利用CGContext的CTM属性对坐标系的宽高进行了缩放倍数,再对图片进行剪裁。该例子还使用了UIImageView对图片的显示,UIScrollView对图片的缩放,移动。
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
//设置剪裁按钮
UIButton* crop = [UIButton buttonWithType:UIButtonTypeCustom];
crop.frame = CGRectMake(0, 0, 60, 30);
[crop setTitle:@"crop" forState:UIControlStateNormal];
[crop setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
crop.backgroundColor = [UIColor grayColor];
crop.alpha = 0.5;
[crop addTarget:self action:@selector(crop:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:crop];