lundi 23 mars 2015

How to call the UIImagePickerControllerSourceTypeCamera continuously

I have the following problem when developing on iOS. I want to achieve that when I'm clicking on a tabbar item the camera shows up. Now that isn't so hard but the problem is this happens once. So when I click on another tabbar item and click back to the camera item, the camera doesn't show up again.


I think this is because when you click on cancel the UIImagePickerController dismisses and doesn't initialize again. How can I solve this problem, that when I'm clicking on the tabbar item the camara will always show up.



class CameraViewController: UIViewController, UIImagePickerControllerDelegate,UINavigationControllerDelegate {

@IBOutlet weak var imageView: UIImageView!
let imagePicker:UIImagePickerController!

override func viewDidLoad() {
super.viewDidLoad();
self.loadCamera();
}


func loadCamera(){

if UIImagePickerController.isSourceTypeAvailable(
UIImagePickerControllerSourceType.Camera) {

imagePicker = UIImagePickerController();
imagePicker.delegate = self;
imagePicker.sourceType = .Camera;

presentViewController(imagePicker, animated: true, completion: nil)

}
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
imagePicker.dismissViewControllerAnimated(true, completion: nil)
imageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage


}


}



Aucun commentaire:

Enregistrer un commentaire