Search code examples
iosswiftuiimagepickercontroller

Calling UIImagePickerController in 4:3 instead of 16:9 (Xcode) (Swift)


I am recording a video through UIImagePickerController and on an iPhone 6s / 6s Plus, it is displayed in 16:9 (simulated by cropping, I imagine) when recording but when the video returns and is laid out, it is 4:3 with the left and right beyond-the-viewfinder parts of the video showing.

How do I have UIImagePickerController in camera mode display in its true 4:3 mode and not in the default faux-16:9?

I am currently calling it as so:

// IB: Record Button Control
@IBAction func recordVideo(_ sender: UIButton) {

    if (UIImagePickerController.isSourceTypeAvailable(.camera)) {

        self.selectedButton = sender

        self.imagePicker.sourceType = .camera
        self.imagePicker.mediaTypes = [kUTTypeMovie as String]
        self.imagePicker.allowsEditing = false
        self.imagePicker.videoMaximumDuration = 30.0
        self.imagePicker.delegate = self

        self.present(self.imagePicker, animated: true, completion: {})

    } else {
        CreateAlert(controller: self, title: "No Camera", message: "Camera is not accessible")
    }

}

Solution

  • Figured this one out. For any of you looking for an answer, ends up that it does this by default if you do not specify a videoQuality.

    As soon as you enter in an videoQuality enum, it returns it the proper way. So I added: self.imagePicker.videoQuality = .typeMedium, it returned the video 16:9.

    For Apple documentation on the different video quality types:

    UIImagePickerControllerQualityType