我有一个非常简单的项目,其中的 View Controller 嵌入在导航 Controller 中。我想推送一个具有透明度的新 View Controller ,这实际上允许底层 Controller 的部分内容显示出来。
在推送转换期间,底层 Controller 的部分确实通过正在推送的新 Controller 显示,但是当转换完成时,底层 Controller View 将从 View 层次结构中删除,并且新 Controller 的透明部分显示出来黑色。
根据 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.
在初始化推送的按钮操作期间,我确实将呈现(推送) View Controller 的 modalPresentationStyle 指定为 UIModalPresentationOverFullScreen:
let semiController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SemiViewController")
semiController.modalPresentationStyle = .overFullScreen
self.navigationController?.pushViewController(semiController, animated: true)
我认为我不必指定自定义转换才能使其工作。那么是什么给了?
谢谢。
最佳答案
您必须呈现您的 Controller ,因为此 modalPresentationStyle 和 modalTransitionStyle 仅在您选择呈现模态方法时才会产生影响。确保半 Controller 主视图的背景颜色保持清晰或不透明度较低
let semiController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SemiViewController")
semiController.modalPresentationStyle = .overCurrentContext
semiController.modalTransitionStyle = .crossDissolve
self.present(semiController, animated: true)
关于ios - 推送新的具有透明度的 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58114107/