首页 文章

iOS 7仅限横向应用程序无法访问照片库

提问于
浏览
4

我有一个只有风景的应用程序,每当我访问照片库时,应用程序都会崩溃(因为 UIImagePickerViewController 正在尝试以纵向模式加载) . App在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`

当我启用纵向模式时,一切正常,但我不想启用纵向模式 . 这是什么解决方法?

4 回答

  • 0

    是的,我在应用程序中有类似的问题

    您可以为应用添加纵向模式支持,但限制所有其他视图仅支持横向,模式,然后图像选择器将起作用

    UIImagePickerViewController 仅适用于纵向模式

    限制其他视图仅支持横向模式,覆盖 - (NSUInteger)supportedInterfaceOrientations在视图控制器中

    - (NSUInteger)supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskLandscape;
    }
    
  • 1

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

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

    UIImagePickerController的CGAffineTransform属性可用于使摄像机处于所需的方向 . imagePicker.cameraViewTransform=CGAffineTransformRotate(yourimagePicker.cameraViewTransform, M_PI/2);

    或者,您也可以使用CGAffineTransformScale将自定义尺寸应用于相机 .

  • 0

    您可以使用简单地呈现imagePicker

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

相关问题