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

亡梦爱人 提交于 2019-12-11 10:22:41

问题


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?

来源:https://stackoverflow.com/questions/34787959/swift-how-to-prevent-uiimagepicker-method-takepicture-from-calling-didfinishp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!