Không thể điều chỉnh hành vi của tính năng cắt/chỉnh sửa UIImagePickerController
theo cách được hỗ trợ. Bạn có khả năng có thể đào sâu vào hệ thống phân cấp/xem phân cấp UIImagePickerController
và cố gắng tìm ra cách thức hoạt động của nó, nhưng đó không phải là một điều rất dễ bảo trì hoặc dễ chịu.
Có nói rằng, UIImagePickerController
là một phân lớp của UINavigationController
, vì vậy không có gì ngăn bạn triển khai trình điều khiển chế độ xem chỉnh sửa hình ảnh của riêng bạn và đẩy nó vào UIImagePickerController
. Điều này có thể sẽ không quá khó, bạn chỉ có thể ném số UIImage
được chọn vào một UIScrollView
với lớp phủ hình chữ nhật hiển thị vùng cắt, thực hiện một số phép toán và tự cắt bớt số UIImage
. Bạn rõ ràng sẽ có toàn quyền kiểm soát các chức năng trong trường hợp này và tôi đặt cược nó sẽ mất ít thời gian để thực hiện hơn spelunking vào ruột của UIImagePickerController
.
tôi có lẽ sẽ đặt nó lên bất cứ điều gì quan điểm điều khiển trình bày bảng chọn như thế này:
@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
Và sau đó xem chỉnh sửa của bạn sẽ có một giao diện như thế này (với một thực hiện cụ thể yêu cầu của bạn):
@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
Nguồn
2013-08-10 17:59:16