首页 文章

如何在仅在iOS-6中支持横向定位的应用中使用UIImagePickerController?

提问于
浏览
3

我正在开发一个仅支持横向定位的应用程序 . 它使用 UIImagePickerController 从库中选择图像和/或视频 . 应用程序在iOS-5或之前运行良好但在我尝试呈现图像选择器控制器时它会崩溃 . 它在崩溃后给出以下消息:

*因未捕获的异常终止应用'UIApplicationInvalidInterfaceOrientation',原因:'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

2 回答

  • 8

    正如@rocky所说,你必须将Potrait模式添加到你的应用程序才能使用 UIImagePickerController 就像这样

    Supported Interface Orientation in Info.plist
    或将此添加到仅限景观的应用委托类

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
        return UIInterfaceOrientationMaskAll;
    }
    

    Mr.Daniel's Answer我找到了一个很好的解决方案,你的仅景观应用程序,因为你只需要支持你的应用程序的景观,你只需要添加一个类别 UINavigationController 像这样

    @implementation UINavigationController (LandscapeOnly)
    
    - (NSUInteger) supportedInterfaceOrientations{
        return UIInterfaceOrientationMaskLandscape;
    }
    @end
    

    并将其添加到您的viewControllers,它适用于我 .

  • 2

    来自UIImagePickerController文档:

    重要说明:UIImagePickerController类仅支持纵向模式 . 此类旨在按原样使用,不支持子类化 . 此类的视图层次结构是私有的,不得修改,但有一个例外 . 您可以将自定义视图分配给cameraOverlayView属性,并使用该视图显示其他信息或管理相机界面与代码之间的交互 .

    如果要使用此控制器,则必须将“纵向”模式添加到“支持”界面方向 .

相关问题