iOS 7 横屏应用无法访问照片库。

5

我有一个仅支持横屏的应用程序,每当我访问照片库时,应用程序都会崩溃(因为 UIImagePickerViewController 尝试在纵向模式下加载)。应用程序在 iOS 5 和 6 中运行良好。

我收到以下错误信息:

终止应用程序由于未捕获异常 'UIApplicationInvalidInterfaceOrientation',原因:'支持的方向与应用程序没有公共方向,并且 shouldAutorotate 返回 YES'

*** First throw call stack:
(0x2ff7ae8b 0x3a2746c7 0x2ff7adcd 0x3277337d 0x3277a4c5 0x3277a47b 0x327795b3 0x326fff3d 0x326ffd19 0x326ff609 0x326ff467 0x3270c153 0x3270bbd3 0x327b7f67 0x327b7d83 0x327afdf3 0x327af279 0x327aefe9 0x327aef7d 0x32700533 0x32387f43 0x32383767 0x323835f9 0x3238300d 0x32382e1f 0x3237cb4d 0x2ff45f71 0x2ff438ff 0x2ff43c4b 0x2feae541 0x2feae323 0x34be52eb 0x327651e5 0x8c439 0x8c3c0)

`libc++abi.dylib:` terminating with uncaught exception of type `NSException`

当我启用纵向模式时,一切都像往常一样,但我不想启用纵向模式。有什么解决办法吗?


可能是重复的问题:iOS7 iPad横屏应用,使用UIImagePickerController - Peter Lapisu
4个回答

8

是的,我在一个应用程序中遇到了类似的问题。

您可以将竖屏模式支持添加到应用程序中,但限制所有其他视图仅支持横向模式,然后图像选择器将起作用。

UIImagePickerViewController 仅在竖屏模式下工作。

要限制其他视图仅支持横向模式,请在您的视图控制器中覆盖 - (NSUInteger)supportedInterfaceOrientations 方法。

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscape;
}

你是如何限制所有其他视图仅支持横屏的?我尝试了各种可能的方法,但当在plist中添加纵向模式支持时,它仍会旋转到纵向。 - Rukshan
在您的视图控制器中添加代码
  • (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscape; }
- lanbo
3
在我的情况下,这种方法不起作用,因为我的根视图控制器是导航控制器。因此,我不得不使用这些方法来子类化导航控制器。然后它就起作用了!谢谢! :) - Rukshan

1

在appdelegate.m文件中添加以下代码片段。这将解决上述问题。

 -(NSUInteger)application:(UIApplication *)application 
supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
     {
         return UIInterfaceOrientationMaskAll;
     }
     else
     {
         return UIInterfaceOrientationMaskAllButUpsideDown;
     }
}

0

您可以使用以下方式简单地呈现imagePicker:

ImagePickerController *imagePickerController=[[ImagePickerController alloc]init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;

0

UIImagePickerController的CGAffineTransform属性可用于将相机旋转到所需方向。 imagePicker.cameraViewTransform = CGAffineTransformRotate(yourimagePicker.cameraViewTransform, M_PI/2);

或者,您还可以使用CGAffineTransformScale来为相机应用自定义大小。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接