【问题标题】:How do I open the gallery on iPhone for selecting images?如何在 iPhone 上打开图库以选择图像?
【发布时间】:2013-06-06 07:48:06
【问题描述】:

我需要知道如何在 iPhone SDK 中打开图库。我相信我的代码是正确的,但我仍然遇到异常。

这是我的代码:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
        imgpkrController.delegate = self;
        imgpkrController.allowsEditing = YES;
        imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];

        [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];}

通过使用此代码,我得到了异常:

UIApplicationInvalidInterfaceOrientation', reason:
  preferredInterfaceOrientationForPresentation must return a supported interface orientation!

所以我尝试了这段代码:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
        UIInterfaceOrientation interface = [[UIApplication sharedApplication] statusBarOrientation];
        if(interface == UIDeviceOrientationPortrait)
        {
            imgpkrController.delegate = self;
            imgpkrController.allowsEditing = YES;
            imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];

            [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];

        }else if (interface ==UIDeviceOrientationLandscapeLeft || interface ==UIDeviceOrientationLandscapeRight)
        {
            imgpkrController.delegate = self;
            imgpkrController.allowsEditing = YES;
            imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            //[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];
            [self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];}}

但这给出了同样的例外。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    我认为您使用的早期代码没有任何问题。为此目的继续使用该代码。我认为 UIInterfaceOrientation 中的代码有问题。你可以试试这个 Go to Target-> Summery -> 然后尝试从那里处理方向。

    如果这没有帮助,那么您需要在以下链接中学习有关 UIInterfaceOrientation 的内容

    http://www.scott-sherwood.com/ios-6-uiapplicationinvalidinterfaceorientation-exception/

    【讨论】:

    • Ankit 我尝试按照您所说的方式进行操作,但无法成功。有没有人可以帮我解决这个问题。
    • imgpkrController 应该已经被定义为一个视图控制器,为什么要在当前模型视图控制器中添加 imgpkrController,例如 (UIViewController *)imgpkrController。
    • 因为这是我知道的唯一方法。如果还有其他方法可以做到这一点,请与我分享。此代码在其他项目上运行良好,但在此项目上不运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    相关资源
    最近更新 更多