Isu*_*uru 2 transparency background alpha-transparency ios swift
我想让视图控制器的视图半透明.为此,我在viewDidLoad方法中设置了这样的背景颜色.
view.backgroundColor = UIColor(white: 0, alpha: 0.5)
Run Code Online (Sandbox Code Playgroud)
当显示视图控制器时,背景显示为我需要它然后它立即变黑.
为什么会这样?
这是显示以下内容的代码PopupViewController:
@IBAction func didTapShowButton(_ sender: UIButton) {
let navController = UINavigationController(rootViewController: PopupViewController())
present(navController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我也在这里上传了一个演示项目.
你可以添加标志overCurrentContext(或custom),所以你present 可能会这样:
@IBAction func didTapShowButton(_ sender: UIButton) {
let navController = UINavigationController(rootViewController: PopupViewController())
navController.modalPresentationStyle = .overCurrentContext
present(navController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)