Swift: how to prevent UIImagePicker takePicture () method from calling didFinishPickingMediaWithInfo

I am developing a custom overlay from my `UIImagePicker

func prepareImagePicker() -> CustomOverlayView {

    self.imagePicker =  UIImagePickerController()
    self.imagePicker.delegate = self
    self.imagePicker.sourceType = .Camera
    self.imagePicker.cameraCaptureMode = .Photo
    self.imagePicker.showsCameraControls = false
    self.imagePicker.modalPresentationStyle = .FullScreen

    //customView stuff
    let customViewController = CustomOverlayViewController(
        nibName:"CustomOverlayViewController",
        bundle: nil
    )
    let customView:CustomOverlayView = customViewController.view as! CustomOverlayView
    customView.frame = self.imagePicker.view.frame
    customView.delegate = self
    return customView

}

@IBAction func takeSnapshot(sender: UIButton) {

    let customView:CustomOverlayView = self.prepareImagePicker()
    presentViewController(imagePicker, animated: true, completion: {
        self.imagePicker.cameraOverlayView = customView
    })

    /*let time = dispatch_time(dispatch_time_t(DISPATCH_TIME_NOW), 1 * Int64(NSEC_PER_SEC))
    dispatch_after(time, dispatch_get_main_queue()) {
        self.startMotionManager()
    }*/
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    self.motionManager.stopDeviceMotionUpdates()
    self.imagePicker.dismissViewControllerAnimated(true, completion: nil)
    let takenPhoto:UIImage = (info[UIImagePickerControllerOriginalImage] as? UIImage)!
    self.imageView.image = takenPhoto
}

      

This works well and il photo is taken correctly. Anyway, as soon as it takePicture()

ends, it didn't wait for me to press the "Take Photo" button and immediately go back to mine UIViewController

, where the photo I just took is displayed in UIImageview

. How can I get to UIImagePicker

wait for a button press before calling didFinishPickingMediaWithInfo

?

+1


source to share





All Articles