Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController not full screen

Since the iOS7 upgrade, I have a weird behaviour of the UIImagePickerController. In this application I am using the UIImagePickerController with a cameraOverlayView.

In iOS6 I called the UIImagePickerController using the following code:

_picker = [[UIImagePickerController alloc] init];

if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
    _picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    _picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
    _picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    _picker.showsCameraControls = NO;
    _picker.navigationBarHidden = NO;
    _picker.toolbarHidden = YES;
    _picker.wantsFullScreenLayout = YES;

    _overlayViewController = [[OverlayViewController alloc] init];
    _overlayViewController.picker = _picker;
    _overlayViewController.frameSize = self.frameSize;
    _overlayViewController.delegate = self;
    _picker.cameraOverlayView = _overlayViewController.view;
}
else {
    _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

}
_picker.delegate = self;

Where the OverlayViewController is an UIViewController, with a transparent background which draws some custom controls on screen.

enter image description here

But now in iOS 7 the camera is drawn through the statusbar and a black bar appears beneath the live camera view.

I can solve this by applying a CGAffineTransformMakeTranslation to the cameraViewTransform property of the UIImagePickerController, but why is this like this?

like image 248
Wim Haanstra Avatar asked Sep 25 '13 13:09

Wim Haanstra


1 Answers

In iOS 7, by default UIViewController views take up the entire screen area including the status bar.

wantsFullScreenLayout

is deprecated and ignored. In some cases, this fix works (in the view controller class):

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
}

In other cases, it's a bit more complicated. It's late here, so see how you go with it. Helpful things to note - in a UIViewController, the following code will give the correct statusbar height on both iOS 6 and iOS 7, should it come to having to align things using CGRect math:

if (UIDeviceOrientationIsLandscape(self.interfaceOrientation)) {
            statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.width;
        } else {
            statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
        }

And then don't forget that in Interface Builder, there are the new "iOS 6 delta" adjustments that allow you to design for iOS 7 and then use offsets to correct for iOS 6.

Anyhow, let me know how you go.

like image 154
iosengineer Avatar answered Oct 19 '22 00:10

iosengineer