UIImagePickerControllerDelegate,UINavigationControllerDelegate>
#pragma mark 进入相册
-(void)intoPhoto
{
UIAlertAction *cancelAction = [UIAlertActionactionWithTitle:@"拍照"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction *_Nonnull action) {
[selfcallTheCamera];
}];
UIAlertAction *sureAction = [UIAlertActionactionWithTitle:@"相册"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction *_Nonnull action) {
[self callTheAlbum];
}];
UIAlertController *alertVC = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"请选择调用方式"preferredStyle:UIAlertControllerStyleAlert];
[alertVC addAction:cancelAction];
[alertVC addAction:sureAction];
[self presentViewController:alertVC animated:YEScompletion:^{
}];
}
//调用相机
-(void)callTheCamera{
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *pickerVC = [[UIImagePickerControlleralloc] init];
pickerVC.delegate = self;
pickerVC.allowsEditing = YES;
//摄像头
pickerVC.sourceType =UIImagePickerControllerSourceTypeCamera;
[selfpresentViewController:pickerVC animated:YEScompletion:nil];
}else{
UIAlertController *alertVC = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"你的设备没有摄像头"preferredStyle:UIAlertControllerStyleAlert];
[selfpresentViewController:alertVC animated:YEScompletion:^{
}];
}
}
//调用相册
-(void)callTheAlbum
{
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *pickerVC = [[UIImagePickerControlleralloc] init];
pickerVC.delegate = self;
pickerVC.allowsEditing = YES;
pickerVC.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
[selfpresentViewController:pickerVC animated:YEScompletion:nil];
}
}
#pragma mark - 拍摄完成后或者选择相册完成后自动调用的方法 -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//得到图片
_imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
// 模态返回
[self dismissViewControllerAnimated:YES completion:nil];
}