iOS - 半透明模态视图 Controller

标签 ios uiviewcontroller uinavigationcontroller modalviewcontroller

我想在当前 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/

相关文章:

ios - UICollectionView.dequeueReusableCell 崩溃

ios - Storyboard的子类 ViewController

ios - 内存泄漏,多个 UIViewControllers 的其他问题

ios - 自定义 View Controller 展示导致导航栏弹跳

ios - 如何在 iOS 中创建带有阴影和 subview 的 UIimageView

ios - 你可以在 Objective C 中将函数存储在数组中吗?

iphone - 对于 iPad/iPhone,我可以检测到用户何时因不活动而打开键盘锁吗?

ios - didMoveToParentViewController 调用了两次

iphone - 如何隐藏或删除 UINavigationController?

ios - Swift:SWReavealController 无法滑动以关闭菜单 "only open with swipe"