如何在iPad中使用UIImagePickerController? [英] How to use UIImagePickerController in iPad?
问题描述
您好我正在开发通用应用程序(iPhone / iPad)。一个功能是我必须从相册中选择一张照片并在UIImageView上显示。
Hi i am working on a universal application (iPhone/iPad). one feature is that i have to select a photo from album and show it on UIImageView.
现在的问题是它在iPhone上运行良好但是当我尝试打开照片时专辑崩溃了。我在动作表委托中的代码是这样的:
Now problem is that it is working good on iPhone but when i try to open photo album it crashes. my code in action sheet delegate is this:
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
if ( ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]))
{
if (buttonIndex == 0)
{
[self lockAllImagesOnTheScreen];
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}
if (buttonIndex == 1)
{
[self lockAllImagesOnTheScreen];
imagePicker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
}
else {
if (buttonIndex == 0)
{
[self lockAllImagesOnTheScreen];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
}
}
else{
if ( ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]))
{
if (buttonIndex == 0)
{
[self lockAllImagesOnTheScreen];
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}
if (buttonIndex == 1)
{
[self lockAllImagesOnTheScreen];
imagePicker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
}
else {
if (buttonIndex == 0)
{
[self lockAllImagesOnTheScreen];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
imagePicker.sourceType= UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:imagePicker animated:YES];
}
}
}
}
任何人都可以帮助我吗?我已经检查了stackOverflow并且也搜索了它但是徒劳无功。
can any body help me out? i have checked on stackOverflow and also googled it but in vain.
推荐答案
UIImagePickerController
必须在iPad上显示 UIPopoverController
。
UIImagePickerController
must be presented with UIPopoverController
on iPad.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromRect:self.selectedImageView.bounds inView:self.selectedImageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popOver = popover;
} else {
[self presentModalViewController:picker animated:YES];
}
编辑:为<添加强大的属性code> UIPopoverController :
@property (nonatomic, strong) UIPopoverController *popOver;
应该在委托方法中解除popover:
The popover should be dismissed in the delegate methods:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
这篇关于如何在iPad中使用UIImagePickerController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!