Wired behaviour of UIImagePickerController while c

2019-08-30 08:03发布

问题:

My entire app is in portrait orientation, only camera view should open in landscape orientation.

I've taking reference of Apple's sample code of UIImagePickerController, https://developer.apple.com/library/ios/samplecode/PhotoPicker/PhotoPicker.zip

In my requirement, I've to force UIImagePickerController to start camera in landscape mode, and need to capture the photos.

I'm aware of this,

The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

I've implemented following way to achieve this,

  1. sub class with UIImagePickerController and where I implemented all required orientation methods. like this, https://stackoverflow.com/a/14618870/1603234
  2. another method : make a category for UIImagePickerController into same class where I am presenting the camera.

    @implementation UIImagePickerController(rotationFixed)
    
    - (BOOL) shouldAutorotate {
        return NO;
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
       return UIInterfaceOrientationLandscapeRight;
    }
    
    - (NSUInteger)supportedInterfaceOrientations{
       return UIInterfaceOrientationMaskLandscape;
    }
    @end
    

but this wont help.

See the screenshots below,

This is correct photo, taken with real camera (iPhone4s camera app)

This is captured within camera from app. Camera view was rotated in side.

  • What I've to correct is, to make correct view for camera of UIImagePickerController

  • Is there a way that I can force a view to capture photos in landscape mode?

  • Why camera rotated inside?

  • With cameraOverlayView can I achieve this?

回答1:

You cannot modify the behavior of the image picker, as documented by Apple.

If you need more functionality than provided by the UIImagePickerController, you can use AV Foundation framework to capture the images.

Apple has a sample application that demonstrates the use of AV Foundation.