iOS - 半透明模态视图控制器 [英] iOS - Semi-transparent modal view controller

查看:450
本文介绍了iOS - 半透明模态视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在当前视图上以模态方式呈现一个视角稍微透明的视图控制器,这样第一个视图在模态视图下略微可见。

I want to present a view controller with a slightly transparent background modally over the current view, such that the first view is slightly visible under the modal view.

I设置模态视图控制器的alpha值,并将 modalPresentationStyle 设置为 UIModalPresentationCurrentContext ,如另一篇文章所示。

I set the alpha value of the modal view controller and set the modalPresentationStyle to UIModalPresentationCurrentContext, as suggested in another post.

结果是视图背景在设置动画时是透明的,但是当视图控制器就位时,它会变为不透明的黑色。它可以恢复透明,同时激活解雇。

The result is that the view background is transparent when animating up, but when view controller is in place it changes to opaque black. It goes back to being transparent while animating the dismissal.

如何在活动时让它变得透明?

How can I get it to be transparent when active ?

我已经在 iOS 6和7 中进行了测试。我使用的代码如下:

I have tested in iOS 6 and 7. The code I am using follows:

MyModalViewController *viewController = [[MyModalViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[navController setNavigationBarHidden:YES];
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self.navigationController presentViewController:navController animated:YES completion:NULL];


推荐答案

iOS 8专门为此增加了一种新的模态演示风格目的:

iOS 8 added a new modal presentation style specifically for this purpose:

presentedViewController.modalPresentationStyle = UIModalPresentationOverFullScreen

来自 spec


UIModalPresentationOverFullScreen

UIModalPresentationOverFullScreen

视图演示样式所呈现的视图覆盖屏幕。演示文稿完成后,不会从视图层次结构中删除所显示内容下方的视图。因此,如果呈现的视图控制器没有用不透明的内容填充屏幕,则底层内容会显示出来。

A view presentation style in which the presented view covers the screen. The views beneath the presented content are not removed from the view hierarchy when the presentation finishes. So if the presented view controller does not fill the screen with opaque content, the underlying content shows through.

这篇关于iOS - 半透明模态视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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