Search code examples
iosswift3orientationuiimagepickercontrollerlandscape-portrait

UIImagePicker opens Photos app in Landscape Mode always


UIImagePicker is always opening photos app in landscape mode while the controller is in portrait mode, and the device orientation is also portrait. Can anyone please help?

enter image description here

func actionSheet(_ actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {

    if buttonIndex == 1 {

        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {

            let controller = UIImagePickerController.init()
            controller.sourceType = UIImagePickerControllerSourceType.camera
            controller.delegate = self
            controller.allowsEditing = true
            self.present(controller, animated: true, completion: { () -> Void in

            })
        }
    }
    else if buttonIndex == 2 {

        let controller = UIImagePickerController.init()
        controller.sourceType = UIImagePickerControllerSourceType.photoLibrary
        controller.delegate = self
        controller.allowsEditing = true
        self.present(controller, animated: true, completion: { () -> Void in

        })
    }
}

Solution

  • Add this line before presenting viewcontroller. hope it will fix the issue

    controller.modalPresentationStyle = .overCurrentContext