UIImagePickerController gallery view does not respect `preferredContentSize`

Number:rdar://38506303 Date Originated:3/15/2018
Status:open Resolved:
Product:iOS Product Version:11.3
Classification:Bug Reproducible:Always
On iPad, when using `preferredContentSize` on UIImagePickerController presented as `.formSheet`, when selecting from the library and navigating to the gallery view after selecting an album, if a layout is triggered, such as a device rotation, the view is resized to compact size instead of maintaining the requested size.

Steps to Reproduce:

1. Use the following to present a UIImagePickerController on an iPad:

class ViewController: UIViewController, UINavigationControllerDelegate {

    static private let preferredContentSize = CGSize(width: 540, height: 710)
    private func showPhotoLibrary() {
        let imagePicker = UIImagePickerController()
        imagePicker.modalPresentationStyle = .formSheet
        imagePicker.delegate = self
        imagePicker.sourceType = .photoLibrary
        imagePicker.preferredContentSize = ViewController.preferredContentSize

        present(imagePicker, animated: true, completion: nil)

2. Select an album, you should now be viewing the collection view of images
3. Rotate the iPad

Expected Results:

Picker maintains width

Actual Results:

Picker resizes to Compact width.


iOS 11.2.5 and 11.3 beta 5


iPad Pro 9.7


You can workaround the problem by implementing the nav controller willShow delegate method thusly:

    public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        viewController.preferredContentSize = ViewController.preferredContentSize


This still happens on iOS 12.

But, It seems that this doesn't happen on iOS 13.

By horitayuya at March 26, 2020, 8:14 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!