gpt4 book ai didi

ios - 透明 View 背景变黑

转载 作者:可可西里 更新时间:2023-11-01 00:20:44 26 4
gpt4 key购买 nike

我想让 View Controller 的 View 半透明。为此,我在 viewDidLoad 方法中设置了这样的背景颜色。

view.backgroundColor = UIColor(white: 0, alpha: 0.5)

当显示 View Controller 时,背景会根据我的需要出现,然后立即变黑。

enter image description here

为什么会这样?

这是显示 PopupViewController 的代码:

@IBAction func didTapShowButton(_ sender: UIButton) {
let navController = UINavigationController(rootViewController: PopupViewController())
present(navController, animated: true, completion: nil)
}

我上传了一个演示项目 here

最佳答案

您可以添加标志 overCurrentContext(或 custom),因此您的present 可能类似于:

@IBAction func didTapShowButton(_ sender: UIButton) {
let navController = UINavigationController(rootViewController: PopupViewController())
navController.modalPresentationStyle = .overCurrentContext
present(navController, animated: true, completion: nil)
}

关于ios - 透明 View 背景变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48044126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com