首页 文章

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

提问于
浏览
0

当控制器处于纵向模式时,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 回答

  • 1

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

    controller.modalPresentationStyle = .overCurrentContext
    

相关问题