UIImagePickerController: Camera preview on iPhone 12 (Pro) at undefined position?

Using UIImagePickerController, on all devices except iPhone 12 and iPhone 12 Pro (and maybe devices that will become available in the future) the camera preview is aligned at the top of the screen. On the iPhone 12 and iPhone 12 Pro (and maybe other iPhone 12 variants), the preview is no longer aligned at the top, but at a position that does not seem to be determinable (guess: about 100 pixels from the top).

This becomes a problem if cameraOverlayView is used to present a mask to the user to help him positioning an object at a specific location within the capture.

The alignment of the preview should be at the top of the screen (as on other devices) or there should be any way to determine the offset. Anyone has any idea how to solve that?

Replies

We have the same problem. There is no way to correctly position the camera view for all devices because the behaviour for each devices are different
Same here.

I have tried to mitigate this using cameraViewTransform and while scaling to adjust to screen works, translating does not. Have tried several ways to create the transform and I can see the transform matrix being applied using a breakpoint.

However, the scaling has effect while the translating (for centring purposes o for mitigating this issue) seem to have no effect.

It only happens in iphone 12; iphone 11 (on both ios 13 and 14 do not exhibit this problem). It seems to me there is a bug in UIImagePickerController implementation.
Things tried and tested on iPhone 12
  • present full screen/present as a modal

  • wrap the picker inside a VC/present UIImagePickerController as is

  • cameraViewTransform: scale then translate/ translate then scale/apply directly/ create a CGAFFineTransform and then apply

  • with overlay/without overlay

None of these combinations worked. Not even just presenting an UIImagePickerController with no transform and no overlay applied, even then there is always a black bar of about 122 points and cameraViewTransform translation does nothing.

I have this same issue, also mentioned in this thread: https://developer.apple.com/forums/thread/662172

I think they changed the camera's view to be centered in the cameraViewTransform on certain devices or screensizes. Unfortunately, I can't find any way to get the coordinates of that nested camera's view.
We're currently facing the same exact problem on iPhone 12 and 12 Pro, our cameraOverlayView doesn't fit the new dimensions.

Any quick solutions / workarounds ?
I am facing the same issue on iPhone 12 series devices. UIImagePickerController is not working properly on these devices, though I have dynamic logic but it is not showing properly. Till iPhone XS Max it is working Properly. Please Help.Need to understand why such behaviour.

I found 121pt Y positions gap by "CAMPreviewView".

<CAMPreviewView: 0x14de74310; frame = (0 121; 375 500); tintColor = <UIDynamicSystemColor: 0x283099840; name = systemYellowColor>; gestureRecognizers = <NSArray: 0x282bafbd0>; layer = <CAMCounterRotatingLayer: 0x28257d040>>

      // get CAMPreviewView from UIImagePickerController
      guard let previewView = findPreviewView(picker.view) else {
        return
      }
              
      let previewViewFrame = previewView.frame
       
      // reset CAMPreviewView frame
      if 0 < previewViewFrame.minY {
        previewView.frame = CGRect(
          x: previewViewFrame.minX,
          y: 0,
          width: previewViewFrame.width,
          height: previewViewFrame.height
        )
      }