如何在我的应用程序中实现“选择现有照片”,如默认的iPhone电话簿?

时间:2011-03-04 09:03:15

标签: iphone objective-c uiimageview capture

我想开发一款应用程序,其功能与iphone电话簿捕获图像和选择iamge相同,

我应该用什么来做这样的

我为UIActionSheet创建了一个UIImageView和一个按钮,

现在我想在我的应用程序中执行“拍照”和“选择现有照片”选项

帮助我,我很感激

提前感谢....

1 个答案:

答案 0 :(得分:10)

嘿@Veer你需要使用UIImagePickerController

查看文档 http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html 并查看此链接

http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/

它有相同的示例。

编辑您可以使用这些方法获取UIImageView对象中的图像

- (void)selectPhotos
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{
    imageView.image = image;
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
}