如何在 iPad 中使用 UIImagePickerController? [英] How to use UIImagePickerController in iPad?

查看:24
本文介绍了如何在 iPad 中使用 UIImagePickerController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个通用应用程序(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];
}

EDIT:为 UIPopoverController 添加一个强属性:

EDIT: Add a strong property for the UIPopoverController:

@property (nonatomic, strong) UIPopoverController *popOver;

应该在委托方法中消除弹出框:

The popover should be dismissed in the delegate methods:

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

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 

这篇关于如何在 iPad 中使用 UIImagePickerController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆