如何在使用 UITapGestureRecognizer 从 UITableViewCell 呈现 UIView 时使它透明?

How to make a UIView transparent while presenting it from UITableViewCell with UITapGestureRecognizer?

我通过点击 UILabel 从 UITableviewCell 显示了一个 UINib(自定义 AlertView)。 UINib 有两个view,一个是自定义alert,background view 是通过透明显示alert view 效果。

@objc func taptakeYourMedsDescriptionLabel(tapGestureRecognizer: UITapGestureRecognizer) {
    let undectableVC = UndetectableAlertVC(nibName: "UndetectableAlertVC", bundle: nil)
    undectableVC.view.backgroundColor = UIColor.black.withAlphaComponent(0.1)
    UIApplication.shared.keyWindow?.rootViewController?.present(undectableVC, animated: true, completion: nil)
 }

我也在UndetectableAlertVC的viewWillAppear中给了undectableVC.view.backgroundColor = UIColor.black.withAlphaComponent(0.1)

问题:视图在呈现时是透明的,但在呈现视图后不久它就会变成黑色。

要求:

谁能帮我解决这个问题?

试试这个

let undectableVC = UndetectableAlertVC(nibName: "UndetectableAlertVC", bundle: nil)
undectableVC.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)

undectableVC.modalPresentationStyle = .custom
undectableVC.modalTransitionStyle = .crossDissolve
self.navigationController?.present(undectableVC, animated: true, completion: nil)