iOS 如何启动图像选择器

标签 ios objective-c uiimagepickercontroller

我有一个 UIButton,当用户点击它时,我想启动图像选择器 Controller

我已经配置了我认为足够的配置,但我不知道我必须传递给该图像选择器以开始工作的消息是什么

这是我的代码

#import "ImagePickerViewController.h"

@interface ImagePickerViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *image;


@end

@implementation ImagePickerViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (IBAction)SelectImage:(id)sender {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}

@end

我已经设置了正确的协议(protocol):

@interface ImagePickerViewController : UIViewController < UINavigationControllerDelegate,UIImagePickerControllerDelegate>

@end

最佳答案

您需要呈现UIImagePicker

- (IBAction)SelectImage:(id)sender
{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
    imagePicker.delegate = self;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:imagePicker animated:NO completion:nil];
}

关于iOS 如何启动图像选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24098887/

相关文章:

ios - 删除 `UIImagePickerController` 缩放 slider

iphone - Xcode:为什么我的计时器在每次滴答时计数 2 秒?

javascript - html <select> jquery 混合起来不工作 ios

ios - 尽管不使用自动布局,但垂直滚动在 UIScrollView 和 iOS7 和 Xcode 5 中不起作用

ios - CATransform3D 打破图层顺序?

objective-c - 在添加的 subview 上未调用drawRect

objective-c - Cocotron是逆向工程的结果吗?

ios - Amazon S3 Cognito - 从图像选择器上传图像 - Swift 3

ios - 应用 anchor 后 CATransform3DRotate 效果消失

ios - 我从 imagepicker 返回后,viewcontroller 中的所有内容都消失了?