简体   繁体   English

使用UIImagePickerController从照片库中访问相机

[英]Accessing camera from within the photo library with UIImagePickerController

There are tons of examples on how to add a button to access the photo library from the camera view, but I can't seem to find anything about doing it the other way around. 关于如何添加按钮以从相机视图访问照片库的示例很多,但我似乎找不到其他方法可以做到这一点。

In my app the primary source of the images would be the library, but I also want to let the users use the camera if they really want to. 在我的应用程序中,图像的主要来源将是库,但我也想让用户在确实需要时使用相机。 If possible I would like to avoid the additional step of presenting an action sheet with the two options (library and camera) or some similar solution. 如果可能的话,我想避免额外的步骤,即提供带有两个选项(库和摄像机)或类似解决方案的操作表。 Also, I would prefer not to have two dedicated buttons. 另外,我不希望没有两个专用按钮。

I use this code: 我使用以下代码:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  self.imgPicker  = [[UIImagePickerController alloc] init];

  if(buttonIndex == 0) {
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
      self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
      self.imgPicker.allowsEditing = NO;
      self.imgPicker.delegate = self;
      self.imgPicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
    }
  }

  if(buttonIndex == 1) {
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])  {
      self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
      self.imgPicker.allowsEditing = NO;
      self.imgPicker.delegate = self;
    }
  }
  [self performSelector:@selector(showPicker) withObject:self afterDelay:0.6f];
}

- (void)showPicker {
  [self presentModalViewController:self.imgPicker animated:YES];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM