当我看到我的视图呈现为黑色背景色时,我有一个问题。这是我的代码:
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)
}
}