我需要知道如何在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];}}
但这给出了同样的例外。任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
我认为您使用的早期代码没有任何问题。为此目的继续使用该代码。我认为 UIInterfaceOrientation 中的代码存在问题。你可以试试这个Go to Target->总结 - >然后尝试从那里处理方向。
如果这没有用,那么您需要在以下链接中研究UIInterfaceOrientation
http://www.scott-sherwood.com/ios-6-uiapplicationinvalidinterfaceorientation-exception/