当提出modally视图控制器时的黑背景

时间:2018-05-28 16:29:01

标签: ios swift user-interface

当我看到我的视图呈现黑色BG颜色时,我遇到了一个问题。这是我的代码:

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 function:

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 个答案:

答案 0 :(得分:0)

你在说:

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

所以视图本身很清晰,你看到窗口背后的黑色。

答案 1 :(得分:0)

你能试试吗

let loader = Loader()
loader.providesPresentationContextTransitionStyle = true;
loader.definesPresentationContext = true;
loader.modalPresentationStyle = .overCurrentContext
self.present(loader, animated: false, completion: nil)
相关问题