Swift: how to prevent UIImagePicker method takePic

2019-08-12 15:18发布

I am developing a customized 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 the photo il correctly taken. Anyway, as soon as takePicture() finishes, it does not wait that I press a "Accept photo" button and immediately returns to my UIViewController where the just taken photo is displayed in UIImageview. How can I force the UIImagePicker to wait that a button is pressed before it calls didFinishPickingMediaWithInfo?

0条回答
登录 后发表回答