【问题标题】:How to implement Take photo or Choose from gallery options in ios [duplicate]如何在ios中实现拍照或从图库选项中选择[重复]
【发布时间】:2019-05-01 22:30:05
【问题描述】:

任何人都可以帮我实现一个功能 --> 当在应用中选择相机选项时,拍照或从图库选项中选择。

【问题讨论】:

  • 您需要 Objective C 或 Swift 中的代码?
  • 到目前为止您尝试过/搜索过/谷歌搜索过什么?
  • 是的,我需要在目标 c 中编码。我尝试通过实现一个带有两个按钮的视图来拍摄照片并从图库中选择。当在应用程序中选择相机选项时,是否还有其他方法可以带上这些按钮。

标签: ios iphone


【解决方案1】:

// 用于相机拍照

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:nil];

// 用于从图库中选择图片

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:picker animated:YES completion:nil];

// 用于输出图像

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

    // output image
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
    self.profileImageView.image = chosenImage;
    [picker dismissViewControllerAnimated:YES completion:nil];

}

别忘了添加 UIImagePickerControllerDelegate 和 UINavigationControllerDelegate。

【讨论】:

  • 我已经做到了。我想在选择相机选项时显示按钮(拍照或使用图库)。你能帮我吗?
  • 您可以使用UIActionsheet 来执行此操作。在您的按钮上点击打开带有两个选项 camara 或照片库的操作表。请参阅此链接stackoverflow.com/questions/17223210/creating-uiactionsheet 以了解如何使用操作表。在操作表的 camara 按钮上打开 camara,对于照片库也是如此
  • 你似乎是新的 iOS 开发者。只是你需要自己定制。与您的团队讨论该 UI。这种问题没有人能帮上忙。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-30
  • 1970-01-01
  • 2016-09-06
  • 2013-10-01
  • 2017-09-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多