【问题标题】:How to make a UIView transparent while presenting it from UITableViewCell with UITapGestureRecognizer?如何在使用 UITapGestureRecognizer 从 UITableViewCell 呈现 UIView 时使其透明?
【发布时间】:2020-06-04 08:07:41
【问题描述】:

我通过点击 UILabel 从 UITableviewCell 展示了一个 UINib(自定义 AlertView)。 UINib 有两个视图,一个用于自定义警报,而背景视图是通过使其透明来显示警报视图效果。

@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)

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

要求:

谁能帮我解决这个问题?

【问题讨论】:

    标签: ios swift uiview


    【解决方案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)
    

    【讨论】:

    • 欢迎点击右箭头,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 2021-01-19
    • 2014-12-06
    • 1970-01-01
    相关资源
    最近更新 更多