无法以UIImagePickerController
受支持的方式调整裁剪/编辑功能的行为。您可能会深入研究UIImagePickerController
控制器/视图层次结构并尝试弄清楚它是如何工作的,但这不是一件易于维护或令人愉快的事情。
话虽如此,UIImagePickerController
是 的子类UINavigationController
,所以没有什么能阻止您实现自己的图像编辑视图控制器并将其推送到UIImagePickerController
. 这可能不会太难,你可以把挑选的UIImage
东西扔进一个UIScrollView
带有显示裁剪区域的矩形覆盖层中,做一些数学运算,然后UIImage
自己裁剪。在这种情况下,您显然可以完全控制功能,我敢打赌,与深入研究UIImagePickerController
.
我可能会设置它像这样呈现选择器的任何视图控制器:
@interface MainViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate, ImageEditorViewControllerDelegate>
@end
@implementation MainViewController {
UIImagePickerController* _imagePickerController;
}
#pragma mark IBAction
- (IBAction)pickImage:(id)sender {
_imagePickerController = [[UIImagePickerController alloc] init];
_imagePickerController.delegate = self;
_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
_imagePickerController.allowsEditing = NO;
[self presentViewController:_imagePickerController animated:YES completion:nil];
}
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
ImageEditorViewController* imageEditorViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ImageEditor"];
imageEditorViewController.delegate = self;
imageEditorViewController.imageToEdit = info[UIImagePickerControllerOriginalImage];
[_imagePickerController pushViewController:imageEditorViewController animated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:^{
_imagePickerController = nil;
}];
}
#pragma mark ImageEditorViewControllerDelegate
- (void)imageEditorViewController:(ImageEditorViewController *)imageEditorViewController didFinishWithInfo:(NSDictionary *)info {
// TODO: Handle the edited media
[self dismissViewControllerAnimated:YES completion:^{
_imagePickerController = nil;
}];
}
@end
然后您的编辑视图将具有这样的界面(具有特定于您需求的实现):
@protocol ImageEditorViewControllerDelegate;
@interface ImageEditorViewController : UIViewController
@property(nonatomic, strong) UIImage* imageToEdit;
@property(nonatomic, weak) id <ImageEditorViewControllerDelegate> delegate;
@end
@protocol ImageEditorViewControllerDelegate
- (void)imageEditorViewController:(ImageEditorViewController*)imageEditorViewController didFinishWithInfo:(NSDictionary*)info;
@end