为了账号安全,请及时绑定邮箱和手机立即绑定

iOS:具有透明背景的Modal ViewController

iOS:具有透明背景的Modal ViewController

翻翻过去那场雪 2019-12-09 10:37:13
我正在尝试以透明背景模态呈现视图控制器。我的目标是让呈现和呈现的视图控制器的视图同时显示。问题是,当演示动画结束时,演示视图控制器的视图消失。- (IBAction)pushModalViewControllerButtonPressed:(id)sender{    ModalViewController *modalVC = [[ModalViewController alloc] init];    [self presentViewController:modalVC animated:YES completion:nil];}我知道我可以将视图添加为子视图,但是出于某种原因,我想避免这种解决方案。我该如何解决?
查看完整描述

3 回答

?
www说

TA贡献1775条经验 获得超8个赞

以下代码仅适用于iPad。


self.view.backgroundColor = [UIColor clearColor];

self.modalPresentationStyle = UIModalPresentationCurrentContext;

[self presentModalViewController:modalVC animated:YES];

我会添加一个子视图。


这是一个很好的讨论。具体看一下评论。不只是答案。


模态视图


如果我是你,我不会做。我将添加一个子视图并执行此操作。看来我可以更好地控制事物。


编辑:


正如Paul Linsay所提到的,自iOS 8起,所需要的只是UIModalPresentationOverFullScreen用于呈现ViewController的modalPresentationStyle。这也将覆盖navigationBar和tabBar按钮。


查看完整回答
反对 回复 2019-12-09
?
不负相思意

TA贡献1777条经验 获得超10个赞

在iOS 8.0及更高版本中,可以通过将modalPresentationStyle属性设置为UIModalPresentationOverCurrentContext来完成


//Set property **definesPresentationContext** YES to avoid presenting over presenting-viewController's navigation bar


self.definesPresentationContext = YES; //self is presenting view controller

presentedController.view.backgroundColor = [YOUR_COLOR with alpha OR clearColor]

presentedController.modalPresentationStyle = UIModalPresentationOverCurrentContext;


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


查看完整回答
反对 回复 2019-12-09
  • 3 回答
  • 0 关注
  • 1176 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信