Swift:如何防止UIImagePicker方法takePicture()调用didFinishPickingMediaWithInfo

时间:2016-01-14 11:03:02

标签: xcode swift uiimagepickercontroller camera-overlay

我正在从我的`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
}

效果很好,照片正确拍摄。无论如何,只要takePicture()完成,它就不会等到我按下“接受照片”按钮并立即返回我的UIViewController,其中刚刚拍摄的照片显示在UIImageview中。在调用UIImagePicker之前,如何强制didFinishPickingMediaWithInfo等待按下按钮?

0 个答案:

没有答案