ios7 CameraPickerController image from camera is f

2019-04-09 13:11发布

问题:

I have this simple code for camera View controller:

UIImagePickerController picker = new UIImagePickerController();
picker.PrefersStatusBarHidden ();
picker.SourceType = UIImagePickerControllerSourceType.Camera;
UIImagePickerControllerCameraDevice dev = picker.CameraDevice;
PresentViewController (picker, false, null);
picker.FinishedPickingMedia += (object sender, UIImagePickerMediaPickedEventArgs e) => BeginInvokeOnMainThread (delegate {DismissViewController (false, null);});

When app starts, I can capture photo normally, but when i present picker again, camera View appears but frame(image) from previous shot is shown and frozen. If i move my device around image doesn't change. In other words, I can use camera once but I can not use it twice. What I am doing wrong? On iOS6 devices it works perfectly.

回答1:

Making a pickerDelegate class did the trick for me. You just have to pass the current VC in the constructor so you can handle the image in your VC.

PickerDelegate

private class pickerDelegate : UIImagePickerControllerDelegate
        {
            private yourVC _vc;

            public pickerDelegate (yourVC controller) : base ()
            {
                _vc = controller;
            }

            public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
            {
               //Do something whit the image
                _vc.someButton.SetBackgroundImage (image, UIControlState.Normal);

                //Dismiss the pickerVC
                picker.DismissViewController (true, null);
            }
        }

ViewDidLoad

imagePicker = new UIImagePickerController ();

//Set the Delegate and pass the current VC
imagePicker.Delegate = new pickerDelegate (this);