1、打开相册

1     UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
2     imagePickerController.delegate = self;
3     imagePickerController.allowsEditing = YES;  //allowsEditing属性 一定要设置成yes,表示照片可编辑,会出现矩形图片选择框 
4     imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
5     [self presentViewController:imagePickerController animated:YES completion:nil];

2、选择图片的任意位置

3、在代理方法中获取编辑后的图片

1 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
 2 {
 3     //退出相册
 4     [picker dismissViewControllerAnimated:YES completion:^{
 5         //原图
 6         UIImage *originalImage = [info objectForKey:UIImagePickerControllerEditedImage];
 7 
 8         //用户选择区域图片
 9         UIImage *editImage = [UIImage fixOrientation:[info objectForKey:UIImagePickerControllerOriginalImage]];
10     }];
11 }

 

为验证次方法的正确性,可以分别打印出两个UIImage对象的frame进行对比.