ios - Push new UIViewController with transparency
问题描述
I have a very simple project with a view controller embedded in a navigation controller. I want to push a new view controller with transparency which in effect allows parts of the underlying controller to show through.
During the push transition, parts of the underlying controller indeed show through the new controller that is being pushed, but when the transition finishes, the underlying controller view is removed from the view hierarchy and the transparent part of the new controller shows up in black.
According to Apple,
When presenting a view controller using the UIModalPresentationFullScreen style, UIKit normally removes the views of the underlying view controller after the transition animations finish. You can prevent the removal of those views by specifying the UIModalPresentationOverFullScreen style instead. You might use that style when the presented view controller has transparent areas that let underlying content show through.
I do specify the modalPresentationStyle of the presented (pushed) view controller to be UIModalPresentationOverFullScreen, during the button action that initialises the push:
let semiController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SemiViewController")
semiController.modalPresentationStyle = .overFullScreen
self.navigationController?.pushViewController(semiController, animated: true)
I don't think I have to specify a custom transition for this to work. So what gives?
Thanks.
解决方案
您必须展示您的控制器,因为此 modalPresentationStyle 和 modalTransitionStyle 只会在您选择呈现模态方法时才会影响。确保保持半控制器主视图的背景颜色清晰或不透明
let semiController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SemiViewController")
semiController.modalPresentationStyle = .overCurrentContext
semiController.modalTransitionStyle = .crossDissolve
self.present(semiController, animated: true)
推荐阅读
- javascript - 谷歌图表错误 - 数据表没有列
- php - Jquery 在 Do-While 循环中未按预期工作
- python - 如何将变量从一个函数调用到另一个函数?
- java - 仅当负前瞻和负后瞻都被统计时才拆分字符串
- npm - 在 Windows 上安装 BuckleScript 时遇到问题
- oracle - 如何在Oracle apex中将信息存储在数据库中以获取具有单个值的复选框和具有多个值的复选框
- serialization - 简单序列化 ODataQueryOptions
- bokeh - 如何从 js 回调中获取旧值和新值?
- android - 我在firebase上做循环和新的我没有从firebase/firestore接收数据尝试从我的keyValue获取数据
- sql - Access SQL - 是否可以按开关值分组?