ios 上传头像 调用摄像头
2021-09-17 本文已影响0人
VickyLanLan
调用
<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
//调用
[self showImagePickerViewController];
@property (nonatomic,strong) UIImagePickerController *imagePicker;
- (void)showImagePickerViewController{
UIAlertController *alertController =[UIAlertController alertControllerWithTitle:@"选取照片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[alertController addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
self.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:self.imagePicker animated:YES completion:nil];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
self.imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:self.imagePicker animated:YES completion:nil];
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
#pragma mark - imagePickerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *image =info[UIImagePickerControllerEditedImage];
if(image){
[self.viewModel.updateHeaderImaeSubject sendNext:image];
}
}
- (UIImagePickerController *)imagePicker{
if (!_imagePicker) {
_imagePicker = [[UIImagePickerController alloc]init];
_imagePicker.delegate = self;
_imagePicker.allowsEditing =YES;
}
return _imagePicker;
}