我想在当前 View 上呈现一个背景稍微透明的 View Controller ,这样第一个 View 在模态视图下稍微可见。
我设置了模态视图 Controller 的 alpha 值,并将 modalPresentationStyle
设置为 UIModalPresentationCurrentContext
,如另一篇文章中所建议的。
结果是 View 背景在向上动画时是透明的,但是当 View Controller 就位时它变成不透明的黑色。它可以在动画解雇时恢复透明。
如何让它在事件时透明?
我已经在 iOS 6 和 7
中测试过。我使用的代码如下:
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 专门为此添加了一种新的模态呈现样式:
presentedViewController.modalPresentationStyle = UIModalPresentationOverFullScreen
来自spec :
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 - 半透明模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18902059/