仅当您在由导航控制器管理的视图控制器中呈现时才会这样。
复制步骤如下:
1 - 使用UIModalPresentationCurrentContext
self.definesPresentationContext = YES;
ViewController* viewController = [[ViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentOnViewController presentViewController:viewController animated:YES completion:nil];
2 - 使用默认的全屏演示文稿样式在顶部显示视图控制器
ViewController* viewController = [[ViewController alloc] init];
[self presentViewController:viewController animated:YES completion:nil];
3 - 关闭顶部呈现的视图控制器(全屏显示)
[self dismissViewControllerAnimated:YES completion:nil];
现在问题是第二个视图控制器(使用UIModalPresentationCurrentContext呈现)消失了。此外,使用UIModalPresentationCurrentContext无法呈现另一个视图控制器,因为系统认为它仍在那里。
答案 0 :(得分:3)
我认为问题是框架中的错误。如上所述,它仅在由导航控制器管理的视图控制器中呈现时发生。有一个讨厌的工作使用包含API。它创建了一个虚拟视图控制器,其中显示了视图。步骤是:
1 - 在上下文中显示父级是导航控制器的视图时,请使用虚拟视图控制器:
- (void)presentInContext
{
UIViewController* presentOnViewController = self;
if ([self.parentViewController isKindOfClass:[UINavigationController class]])
{
// Work around - Create an invisible view controller
presentOnViewController = [[DummyViewController alloc] init];
presentOnViewController.view.frame = self.view.frame;
// Containment API
[self addChildViewController:presentOnViewController];
[self.view addSubview:presentOnViewController.view];
[presentOnViewController didMoveToParentViewController:self];
presentOnViewController.definesPresentationContext = YES;
}
ViewController* viewController = [[ViewController alloc] init];
viewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[presentOnViewController presentViewController:viewController animated:YES completion:nil];
}
2 - 解除视图控制器整理时
- (void)dismissSelf
{
__weak UIViewController* presentingViewController = self.presentingViewController;
[self dismissViewControllerAnimated:YES completion:^{
// Remove the dummy view controller
if ([presentingViewController isKindOfClass:[DummyViewController class]])
{
[presentingViewController willMoveToParentViewController:nil];
[presentingViewController.view removeFromSuperview];
[presentingViewController removeFromParentViewController];
}
}];
}
多数民众赞成......修复很脏,但没有视觉闪烁的技巧。