[英]Dismissing custom modal view controller
I am loading a UIImagePickerController in this way: 我以这种方式加载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];
}
The problem is that I don't know how to dismiss it. 问题是我不知道如何解散它。 When I try 当我尝试
[cameraController dismissViewControllerAnimated:YES completion: nil];
The cameracontroller still is not removed from the screen 仍未从屏幕上删除cameracontroller
To present a view controller modally, you should use this method: 要以模态显示视图控制器,应使用以下方法:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);
To dismiss a modal view controller, you should use this method: 要关闭模式视图控制器,应使用以下方法:
- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);
Per the inline comment above these methods ( UIViewController.h
): 根据这些方法( 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.
Here's what's wrong with your code: 这是您的代码的问题所在:
You're using the deprecated method to present your modal view controller and trying to dismiss it with the new method... this won't work. 您正在使用不推荐使用的方法来呈现模态视图控制器,并尝试使用新方法将其关闭...这将无法工作。
change this 改变这个
[customCamera presentModalViewController:cameraController animated:YES];
with this 有了这个
[self presentViewController:cameraController animated:YES completion:nil];
and dismiss code type this 并关闭此代码
[self dismissViewControllerAnimated:YES completion:nil];
I hope this will help you 我希望这能帮到您
[self dismissViewControllerAnimated:YES completion:nil];
happy coding... 快乐的编码...
If you are adding ViewController as modal - use: 如果要将ViewController添加为模态-使用:
[self dismissModalViewControllerAnimated:YES];
inside your view controller. 在您的视图控制器中。
Please be aware of fact the both functions with "Modal" in name were deprecated in iOS 6.0. 请注意,iOS 6.0中已不推荐使用名称为“ Modal”的两个功能。 Use presentViewController:animated:completion: instead. 请改用presentViewController:animated:completion:。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.