如何连续调用UIImagePickerControllerSourceTypeCamera

时间:2015-03-23 10:00:02

标签: ios iphone

在iOS上进行开发时遇到以下问题。当我点击相机显示的标签栏项目时,我希望实现这一点。现在不是那么难,但问题是这发生一次。因此,当我单击另一个标签栏项目并单击返回相机项目时,相机不会再次显示。

我认为这是因为当你点击取消时,UIImagePickerController会解散并且不会再次初始化。如何解决这个问题,当我点击标签栏时,卡马拉总是会出现。

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


    }


}

1 个答案:

答案 0 :(得分:0)

您可以直接从UITabbarController的派生类中呈现UIImagePickerController。

使UIImagePickerController成为CameraViewController的子视图,并从UITabbarController的派生类中呈现CameraViewController。