iOS调用系统相册或者相机选择照片

UIActionSheet *sheet;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

  sheet = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择",@"拍照", nil];

}else{

   sheet = [[UIActionSheet alloc] initWithTitle:@"选择" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册选择" , nil] ;

}

[sheet showInView:self.view];

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

  if (buttonIndex == actionSheet.cancelButtonIndex) {

  return;

  }

  NSInteger sourceType = 0;

  if (buttonIndex == 0) {

  sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

  }else if (buttonIndex == 1){

  sourceType = UIImagePickerControllerSourceTypeCamera;

  }

  UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];

  pickerController.sourceType= sourceType;

  pickerController.delegate = self;

  pickerController.allowsEditing = YES;

  [self presentViewController:pickerController animated:YES completion:nil];

}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{

[picker dismissViewControllerAnimated:YES completion:nil];

UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容