我正在制作改变现实的应用程序。我的主控制器派生自UIImagePickerController。以下是我创建它的方法:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (!self.overlayController) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.showsCameraControls = false;
self.allowsEditing = false;
self.overlayController = [[[ControlsViewController alloc] initWithNibName:@"ControlsViewController" bundle:[NSBundle mainBundle] picker:self] autorelease];
[self.view addSubview:self.overlayController.view]; // need to add as subview otherwise mouse events captured by UIImagePickerController
self.overlayController.view.frame = CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height);
}
}
[cameraControls setCamera:self];
}
基本上控制器存在于应用程序的整个生命周期中。现在,当我在大多数时间下面用代码拍照时它工作正常,但有时候没有调用.FinishPickingMediaWithInfo。通常的行为是我看到相机焦点开始调整模糊输入/输出然后它稳定,但didFinishPickingMediaWithInfo永远不会被调用。看起来如果相机进入某种校准模式,它可能不会触发此事件。谁有解决方案?我希望可能会有某种额外的回调(比如我错过的错误处理)。 当相机进入奇怪的校准模式时,我甚至可以听到相机快门模拟声音中断。
//self.cameraPicker points to the instance of my main controller that I created earlier
-(void) setCamera:(UIImagePickerController *)picker {
self.cameraPicker = picker;
picker.delegate = self;
}
-(void) takePicture {
[self.cameraPicker takePicture];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(@"Picture ready");
}