iOS:具有透明背景的Modal ViewController [英] iOS: Modal ViewController with transparent background

查看:302
本文介绍了iOS:具有透明背景的Modal ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to present a view controller modally, with a transparent background. My goal is to let both the presenting and presented view controllers's view to be displayed at the same time. The problem is, when the presenting animation finishes, the presenting view controller's view disappears.

- (IBAction)pushModalViewControllerButtonPressed:(id)sender
{
    ModalViewController *modalVC = [[ModalViewController alloc] init];
    [self presentViewController:modalVC animated:YES completion:nil];
}

我知道我可以将视图添加为子视图,但我会喜欢出于某种原因避免这种解决方案。我该怎么办?

I know I could just add the view as a subview, but I'd like to avoid this solution for some reason. How could I fix it?

推荐答案

以下代码仅适用于iPad。

This following code only works on the iPad.

self.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:modalVC animated:YES];

我会添加子视图。

这是一个非常好的讨论。具体看一下评论。不仅仅是答案。

Here is a very good discussion. Look at the comments specifically. Not only the answer.

模态视图

如果我是你,我就不会这样做。我会添加一个子视图并执行它。这似乎让我更好地控制了事情。

If I were you I wouldn't do it. I would add a sub view and do it. It seems to give me a better control over things.

编辑:

正如Paul Linsay所提到的,因为iOS 8所需要的只是 UIModalPresentationOverFullScreen ,用于显示的ViewController的modalPresentationStyle。这也包括navigationBar和tabBar按钮。

As mentioned by Paul Linsay, since iOS 8 all that's needed is UIModalPresentationOverFullScreen for the modalPresentationStyle of the ViewController being presented. This would also cover of navigationBar and tabBar buttons.

这篇关于iOS:具有透明背景的Modal ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆