0

我需要知道如何在 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];}}

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

4

1 回答 1

0

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

如果这没有帮助,那么您需要在以下链接中研究 UIInterfaceOrientation

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

于 2013-06-06T08:20:23.210 回答