捕获照片时UIImagePickerController的有线行为

时间:2014-06-25 13:06:06

标签: ios uiimagepickercontroller landscape uiinterfaceorientation

我的整个应用都处于纵向,只有相机视图才能横向打开。

我已经参考了Apple的UIImagePickerController示例代码, https://developer.apple.com/library/ios/samplecode/PhotoPicker/PhotoPicker.zip

根据我的要求,我强制UIImagePickerController以横向模式启动相机,并需要拍摄照片。

我意识到这一点,

  

UIImagePickerController类仅支持纵向模式。这个   class旨在按原样使用,不支持子类化。   此类的视图层次结构是私有的,不得修改,   除了一个例外。您可以为自定义视图分配   cameraOverlayView属性并使用该视图来显示其他内容   信息或管理相机界面之间的交互   和你的代码。

我已实现以下方式实现此目的,

  1. 具有UIImagePickerController的子类,我实现了所有必需的方向方法。像这样,https://stackoverflow.com/a/14618870/1603234
  2. 另一种方法:将UIImagePickerController的类别放入我展示相机的同一个类中。

    @implementation UIImagePickerController(rotationFixed)
    
    - (BOOL) shouldAutorotate {
        return NO;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
       return UIInterfaceOrientationLandscapeRight;
    }
    
    - (NSUInteger)supportedInterfaceOrientations{
       return UIInterfaceOrientationMaskLandscape;
    }
    @end
    
  3. 但这不会有帮助。

    请参阅下面的屏幕截图

    这是正确的照片,用真实相机拍摄(iPhone4s相机应用程序) enter image description here

    这是从app中的相机中捕获的。相机视图在侧面旋转。 enter image description here

    • 我要纠正的是,为UIImagePickerController

    • 的相机正确观看
    • 有没有办法可以强制视图以横向模式捕捉照片?

    • 为什么相机在里面旋转?

    • 使用cameraOverlayView可以达到此目的吗?

1 个答案:

答案 0 :(得分:0)

您无法修改图像选择器的行为,如Apple所述。

如果您需要比UIImagePickerController提供的功能更多的功能,您可以使用AV Foundation框架来捕获图像。

Apple有sample application演示了AV Foundation的使用。