iOS - 半透明模态视图控制器 [英] iOS - Semi-transparent modal view controller
问题描述
我想在当前视图上模态地呈现一个具有略微透明背景的视图控制器,这样第一个视图在模态视图下略微可见.
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.
我设置了模态视图控制器的 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
来自 规范:
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屋!