5

UIImagePickerController를 사용하여 사용자가 내 응용 프로그램에서 사용할 사진을 업로드 할 수있게합니다. 업로드 할 사진을 선택한 후 사용자는 자신의 사진을 자르라는 메시지를 표시합니다 (이후 imagePickerController.allowsEditing = YES로 설정). 그러나 사진이 가로 방향 (즉, 세로보다 큼) 인 경우 정사각형 이미지를 출력하지 않는 방식으로 사진을자를 수 있습니다. 이는 가로 사진을자를 때 기본 확대/축소 레벨이 aspectFill이 아닌 aspectFit (세로 사진의 경우와 동일)이기 때문입니다.UIImagePickerController 자르기 최소 확대/축소 수준 설정

UIImagePickerController의 편집 모드에서 최소 줌 레벨을 설정할 수 있습니까? 출력이 사각형이 아닌 경우 이미지를 자르면 자동으로 이미지를자를 수 있지만 UIImagePickerController의 편집 모드를 사용하면 대신 사용자에게 전달할 것입니다.

답변

1

자르기/편집 기능의 동작을 지원되는 방식으로 조정할 수 없습니다. UIImagePickerController 컨트롤러/뷰 계층 구조를 파헤쳐서 어떻게 작동하는지 파악하려고 시도 할 수는 있지만 유지 관리가 쉽지 않거나 즐거운 일은 아닙니다.

UIImagePickerControllerUINavigationController의 하위 클래스이므로 사용자가 자신의 이미지 편집보기 컨트롤러를 구현하고 UIImagePickerController에 밀어 넣는 것을 막을 수는 없습니다. 이것은 아마도 너무 어렵지 않을 것입니다. 수확 된 영역을 보여주는 직사각형 오버레이로 UIImageUIScrollView에 던집니다. 몇 가지 수학을 수행하고 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