我正在以这种方式加载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];
相机控制器仍未从屏幕上移除
答案 0 :(得分: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.
以下是您的代码出了什么问题:
您正在使用已弃用的方法来展示您的模态视图控制器并尝试使用新方法将其解除...这不起作用。
答案 1 :(得分:2)
更改此
[customCamera presentModalViewController:cameraController animated:YES];
用这个
[self presentViewController:cameraController animated:YES completion:nil];
并解除代码类型
[self dismissViewControllerAnimated:YES completion:nil];
答案 2 :(得分:1)
我希望这会对你有所帮助
[self dismissViewControllerAnimated:YES completion:nil];
快乐的编码......
答案 3 :(得分:-2)
如果要将ViewController添加为模态 - 请使用:
[self dismissModalViewControllerAnimated:YES];
在视图控制器中。
请注意,iOS 6.0中不推荐使用名称中“Modal”的两个函数。使用presentViewController:animated:completion:而不是。