问题
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