美文网首页
ios 上传头像 调用摄像头

ios 上传头像 调用摄像头

作者: VickyLanLan | 来源:发表于2021-09-17 11:43 被阅读0次
    调用 <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; }

    相关文章

      网友评论

          本文标题:ios 上传头像 调用摄像头

          本文链接:https://www.haomeiwen.com/subject/nxbjgltx.html