Enabling the photo library button on the UIImagePickerController

后端 未结 5 1975
庸人自扰
庸人自扰 2021-02-02 13:26

Does anyone know how to enable the photo album button on the UIImagePickerController when its in the camera mode? Like how the camera app on on the iphone can toggle between ima

5条回答
  •  一个人的身影
    2021-02-02 14:32

    Swift2 version of @epsilontik code:

        //mediaPicker is your UIImagePickerController
    func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
        if(mediaPicker.sourceType == UIImagePickerControllerSourceType.PhotoLibrary){
            let button = UIBarButtonItem(title: "Take picture", style: UIBarButtonItemStyle.Plain, target: self, action: "showCamera")
            viewController.navigationItem.rightBarButtonItem = button
        }else{
            let button = UIBarButtonItem(title: "Choose picture", style: UIBarButtonItemStyle.Plain, target: self, action: "choosePicture")
            viewController.navigationItem.rightBarButtonItem = button
            viewController.navigationController?.navigationBarHidden = false
            viewController.navigationController?.navigationBar.translucent = true
        }
    }
    
    func showCamera(){
        mediaPicker.sourceType = UIImagePickerControllerSourceType.Camera
    }
    
    func choosePicture(){
        mediaPicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    }
    

提交回复
热议问题