iOS:具有透明背景的Modal ViewController

我正在尝试以透明背景模态呈现视图控制器。我的目标是让呈现和呈现的视图控制器的视图同时显示。问题是,当演示动画结束时,演示视图控制器的视图消失。


- (IBAction)pushModalViewControllerButtonPressed:(id)sender

{

    ModalViewController *modalVC = [[ModalViewController alloc] init];

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

}

我知道我可以将视图添加为子视图,但是出于某种原因,我想避免这种解决方案。我该如何解决?


翻翻过去那场雪
浏览 1178回答 3
3回答

www说

以下代码仅适用于iPad。self.view.backgroundColor = [UIColor clearColor];self.modalPresentationStyle = UIModalPresentationCurrentContext;[self presentModalViewController:modalVC animated:YES];我会添加一个子视图。这是一个很好的讨论。具体看一下评论。不只是答案。模态视图如果我是你,我不会做。我将添加一个子视图并执行此操作。看来我可以更好地控制事物。编辑:正如Paul Linsay所提到的,自iOS 8起,所需要的只是UIModalPresentationOverFullScreen用于呈现ViewController的modalPresentationStyle。这也将覆盖navigationBar和tabBar按钮。

不负相思意

在iOS 8.0及更高版本中,可以通过将modalPresentationStyle属性设置为UIModalPresentationOverCurrentContext来完成//Set property **definesPresentationContext** YES to avoid presenting over presenting-viewController's navigation barself.definesPresentationContext = YES; //self is presenting view controllerpresentedController.view.backgroundColor = [YOUR_COLOR with alpha OR clearColor]presentedController.modalPresentationStyle = UIModalPresentationOverCurrentContext;[self presentViewController:presentedController animated:YES completion:nil];
打开App,查看更多内容
随时随地看视频慕课网APP