2
votes

I am experiencing an issue when using the iPad Camera in iOS 8. I've seen some older questions and a thread on the Apple Developer Forums from during the beta but still haven't find a solution.

There seems to be two parts to this issue.

1) The camera itself rotates when the device orientation rotates, eg the world is on its side

2) When opening the camera in Landscape, the overlay does not appear. When opened in Portrait it is fine.

It is an app using iOS7 as the Base SDK, problem only occurs when running the app on a device that has been upgraded to iOS8. The app is not using storyboards, it is using nibs.

I'm hoping to push out a fix for this with Xcode 5.1.1 before moving onto the iOS8 specific fixes and using it as a Base SDK in the next version.

Here is my code to bring up the camera:

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) {

    // Create Camera

    imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;
    imagePicker.showsCameraControls = NO;

    // Set up custom controls view

    [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
    self.overlayView.frame = imagePicker.cameraOverlayView.frame;
    imagePicker.cameraOverlayView = self.overlayView;
    self.overlayView = nil;

    // Show Camera

    [self presentViewController:imagePicker animated:NO completion:nil];

    [imagePicker release];

}

I have also tried

And the Layout of the Toolbar (sitting at the bottom) of the OverlayView:

Toolbar Layout

If I change that to sit "at the top" it appears in both portrait and landscape! So it must have to do with the view/window/something size, though it's strange how its behaviour would change when the layout has stayed the same.

I have tried it with both showsCameraControls = YES and hashing out the OverlayView block, and problem #1 persists so it's not to do with the overlay at app.

I'm hoping someone has found an answer to this, it seems like quite a common problem.

Please let me know if you need any further details.

Edit 1: Fixed the Overlay (Issue #2)

It wasn't applying the orientation to the OverlayView, fixed it like this:

// Grab the window frame and adjust it for orientation - from http://stackoverflow.com/a/15707997/520902

UIView *rootView = [[[UIApplication sharedApplication] keyWindow]
                        rootViewController].view;
CGRect originalFrame = [[UIScreen mainScreen] bounds];
CGRect screenFrame = [rootView convertRect:originalFrame fromView:nil];
...
self.overlayView.frame = imagePicker.cameraOverlayView.frame;

I suspect that it's related to the camera not realising it's orientated too, will keep searching for a fix for Problem #1.

Edit 2: Update on Issue #1

Looks like the camera rotating might be an Apple issue. On iOS8 if you open up the Contacts app, edit a contact and choose 'Take Photo', the exact same issue occurs - in a default Apple app!

I still can't find a fix so I am just destroying and recreating the imagePicker on each orientation change for now, it's ugly but will suffice until Apple release a fix or a better solution pops up.

1
me too facing the same issue. please helpRashmi Ranjan mallick
Hi how do you destroy and recreate the image picker on each rotation? Do you close it down, open it up and then it is portrait mode each time?Lennie
Hi @Lennie, with the change in Edit #1 opening the camera in Portrait or Landscape has the overlay displaying correctly, it's just the actual rotation that is broken. In a trigger of UIDeviceOrientationDidChangeNotification just close and open the camera. This opens it in the current orientation (instead of rotating it to the new orientation) and loads the overlay fine.Batnom
You didn't use ARC even in iOS 8? OMG.Raptor

1 Answers

3
votes

Apple fixed this problem in iOS 8.1.