代码之家  ›  专栏  ›  技术社区  ›  Ruslan Pitula

显示模态视图控制器时的黑色背景

  •  -2
  • Ruslan Pitula  · 技术社区  · 7 年前

    当我看到我的视图呈现为黑色背景色时,我有一个问题。这是我的代码:

    class Loader: UIViewController, NVActivityIndicatorViewable {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.modalPresentationStyle = .currentContext
        self.view.backgroundColor = .clear
        self.view.isOpaque = false
        let width = UIScreen.main.bounds.width
        let height = UIScreen.main.bounds.height
        let frame = CGRect(x: width / 2, y: height / 2, width: 100, height: 100)
        let activityIndicatorView = NVActivityIndicatorView(frame: frame, type: NVActivityIndicatorType.lineScale, color: GlobalVariables.stacksBlue, padding: 20)
        self.view.addSubview(activityIndicatorView)
        activityIndicatorView.startAnimating()
        activityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
        activityIndicatorView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        activityIndicatorView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    }
    

    其中的扩展名是call函数:

    extension UIViewController {
    func showLoader() {
        let loader = Loader()
        self.modalPresentationStyle = .currentContext
        self.present(loader, animated: false, completion: nil)
    }
    func hideLoader() {
        self.dismiss(animated: false, completion: nil)
    }
    

    }

    2 回复  |  直到 7 年前
        1
  •  0
  •   Shehata Gamal    7 年前

    你能试试吗

    let loader = Loader()
    loader.providesPresentationContextTransitionStyle = true;
    loader.definesPresentationContext = true;
    loader.modalPresentationStyle = .overCurrentContext
    self.present(loader, animated: false, completion: nil)
    
        2
  •  0
  •   matt    7 年前

    你是说:

    self.view.backgroundColor = .clear
    self.view.isOpaque = false
    

    所以,视野本身是清晰的,你看到的是它后面窗户的黑暗。