ios - 推送新的具有透明度的 UIViewController

标签 ios uinavigationcontroller transparency pushviewcontroller

我有一个非常简单的项目,其中的 View Controller 嵌入在导航 Controller 中。我想推送一个具有透明度的新 View Controller ,这实际上允许底层 Controller 的部分内容显示出来。

enter image description here

在推送转换期间,底层 Controller 的部分确实通过正在推送的新 Controller 显示,但是当转换完成时,底层 Controller View 将从 View 层次结构中删除,并且新 Controller 的透明部分显示出来黑色。

enter image description here

根据 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/

相关文章:

video - (FFMPEG) 在用透视图覆盖视频之前使区域透明

ios - AVAudioPlayer 在我从 iOS 的资源包中删除歌曲后继续播放歌曲

ios - 禁用 RightBarButtonItems

ios - 尽管导航栏出现在屏幕上,但运行模拟器时导航项不出现

python - 使用 PIL 粘贴的图像会产生伪像

.NET Compact Framework 3.5 动画透明等待光标

javascript - 在 Titanium SDK 中保存和检索 HTML 和 .aspx 网页

iphone - 如何从iPhone应用程序链接到iTunes store应用程序中的“特色音乐”部分?

ios - ios5中的自动旋转——失败的最常见原因?

iphone - 如何将两个 UIBarButtonItem 添加到 UINavigationItem?