我发现了很多关于使用 UIImagePickerController 让用户从照片应用程序的数据中选择他们想要的图像的信息。我想知道如何在 3.0 上创建相同的效果,因为很多旧代码似乎不再有效。此外,我希望用户能够从同一个弹出窗口中拍摄一张新照片。
谢谢你的帮助!
我发现了很多关于使用 UIImagePickerController 让用户从照片应用程序的数据中选择他们想要的图像的信息。我想知道如何在 3.0 上创建相同的效果,因为很多旧代码似乎不再有效。此外,我希望用户能够从同一个弹出窗口中拍摄一张新照片。
谢谢你的帮助!
在 3.0 中工作,和以前一样;我不相信有任何变化。我只是分配/初始化一个 UIImagePickerController,并将其传递给 presentModalViewController,如下所示:
- (void) chooseImageFromLibrary {
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsImageEditing = YES;
[self presentModalViewController:imagePickerController animated:YES];
}
- (void) chooseImageFromCamera {
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.allowsImageEditing = YES;
[self presentModalViewController:imagePickerController animated:YES];
}
也实现委托方法:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
// Do something with the image here.
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}