1

我正在以这种方式加载 UIImagePickerController:

- (void) launchCamera {

// Set up the camera
CustomCamera *cameraController = [[CustomCamera alloc] init];
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraController.delegate = self;

cameraController.showsCameraControls = NO;
cameraController.navigationBarHidden = YES;
cameraController.toolbarHidden = YES;

// overlay on top of camera lens view
UIImageView *cameraOverlayView = [[UIImageView alloc] initWithImage:[UIImage   imageNamed:@"camera_overlay.png"]];
cameraOverlayView.alpha = 0.0f;
cameraController.cameraOverlayView = cameraOverlayView;

// animate the fade in after the shutter opens
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:2.2f];
cameraOverlayView.alpha = 1.0f;
[UIView commitAnimations];

[customCamera presentModalViewController:cameraController animated:YES];
}

问题是我不知道如何解雇它。当我尝试

 [cameraController dismissViewControllerAnimated:YES completion: nil];

相机控制器仍未从屏幕上移除

4

4 回答 4

4

要以模态方式呈现视图控制器,您应该使用以下方法:

 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);

要关闭模式视图控制器,您应该使用以下方法:

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);

根据这些方法(UIViewController.h)上方的内联注释:

The next two methods are replacements for presentModalViewController:animated and dismissModalViewControllerAnimated: The completion handler, if provided, will be invoked after the presented controllers viewDidAppear: callback is invoked.

这是您的代码有什么问题:

您正在使用不推荐使用的方法来呈现您的模态视图控制器并尝试使用新方法将其关闭......这不起作用。

于 2013-09-12T09:47:08.243 回答
2

改变这个

[customCamera presentModalViewController:cameraController animated:YES];

有了这个

[self presentViewController:cameraController animated:YES completion:nil];

并关闭代码类型

[self dismissViewControllerAnimated:YES  completion:nil];
于 2013-09-12T13:38:49.133 回答
1

我希望这能帮到您

[self dismissViewControllerAnimated:YES  completion:nil];

快乐的编码...

于 2013-09-12T09:29:54.360 回答
-2

如果您将 ViewController 添加为模态 - 使用:

 [self dismissModalViewControllerAnimated:YES];

在您的视图控制器内。

请注意,名称中带有“Modal”的这两个函数在 iOS 6.0 中已被弃用。使用 presentViewController:animated:completion: 代替。

于 2013-09-12T09:27:51.797 回答