Ios 取消自定义模态视图控制器

Ios 取消自定义模态视图控制器,ios,cocoa-touch,Ios,Cocoa Touch,我以以下方式加载UIImagePickerController: - (void) launchCamera { // Set up the camera CustomCamera *cameraController = [[CustomCamera alloc] init]; cameraController.sourceType = UIImagePickerControllerSourceTypeCamera; cameraController.delegate = self; cam

我以以下方式加载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];

如果要将ViewController添加为模式,则cameracontroller仍不会从屏幕中删除-使用:

 [self dismissModalViewControllerAnimated:YES];
在视图控制器内部


请注意,名称为“Modal”的两个函数在iOS 6.0中都已被弃用。改为使用presentViewController:animated:completion:。

如果要将ViewController添加为模式,请使用:

 [self dismissModalViewControllerAnimated:YES];
在视图控制器内部


请注意,名称为“Modal”的两个函数在iOS 6.0中都已被弃用。改为使用presentViewController:animated:completion:。

我希望这将对您有所帮助

[self dismissViewControllerAnimated:YES  completion:nil];

快乐编码…

我希望这会对您有所帮助

[self dismissViewControllerAnimated:YES  completion:nil];

快乐编码…

要以模式显示视图控制器,应使用以下方法:

 - (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);
要解除模态视图控制器,应使用以下方法:

 - (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
):

接下来的两个方法是presentModalViewController:animated和dismissModalViewControllerAnimated的替代方法:如果提供了完成处理程序,则将在显示的控制器ViewDidDisplay:callback被调用后调用。

下面是您的代码的问题:


您正在使用不推荐的方法来显示您的模态视图控制器,并尝试使用新方法来消除它。。。这不起作用。

要以模式显示视图控制器,应使用以下方法:

 - (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);
要解除模态视图控制器,应使用以下方法:

 - (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
):

接下来的两个方法是presentModalViewController:animated和dismissModalViewControllerAnimated的替代方法:如果提供了完成处理程序,则将在显示的控制器ViewDidDisplay:callback被调用后调用。

下面是您的代码的问题:

您正在使用不推荐的方法来显示您的模态视图控制器,并尝试使用新方法来消除它。。。这行不通。

更改此选项

[customCamera presentModalViewController:cameraController animated:YES];
用这个

[self presentViewController:cameraController animated:YES completion:nil];
然后关闭此类型的代码

[self dismissViewControllerAnimated:YES  completion:nil];
改变这个

[customCamera presentModalViewController:cameraController animated:YES];
用这个

[self presentViewController:cameraController animated:YES completion:nil];
然后关闭此类型的代码

[self dismissViewControllerAnimated:YES  completion:nil];

正如我在回答中提到的-检查我上次的编辑,因为此方法已被取消种族歧视。@GrzegorzKrukowski,此方法未被弃用。。。签名中带有
modal
的方法已被弃用。检查
UIViewController.h
以获得证据。@JRG开发人员的问题是,他正在使用不推荐的方法来显示ViewController-这是主要问题,它不能与新方法一起工作。在粘贴在问题描述中的代码中,您看到他正在使用它,但它不起作用…@GrzegorzKrukowski,是的,这个答案是错误的-请删除它-它不会解决问题。正如我的答案中提到的-检查我的上一次编辑,因为此方法已被取消权限。@GrzegorzKrukowski,此方法未被弃用。。。签名中带有
modal
的方法已被弃用。检查
UIViewController.h
以获得证据。@JRG开发人员的问题是,他正在使用不推荐的方法来显示ViewController-这是主要问题,它不能与新方法一起工作。在粘贴在问题描述中的代码中,您可以看到他正在使用它,但它不起作用…@GrzegorzKrukowski,YepSo此答案是错误的-请删除它-它不会解决问题。好的,谢谢您将我的评论总结为答案。现在应该清楚了。好的,谢谢你把我的评论总结成答案。现在应该清楚了。