UIImagePicker始终以横向模式打开照片应用

时间:2017-10-18 09:55:35

标签: ios swift3 orientation uiimagepickercontroller landscape-portrait

当控制器处于纵向模式时,UIImagePicker始终以横向模式打开照片应用程序,并且设备方向也是纵向。有人可以帮忙吗?

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

        })
    }
}

1 个答案:

答案 0 :(得分:1)

在呈现viewcontroller之前添加此行。希望它能解决问题

controller.modalPresentationStyle = .overCurrentContext