我已将UIView()
添加到UIApplication.shared.keyWindow
,因此它会覆盖整个屏幕。
到那个UIView
我添加一个渐变颜色作为子图层(我认为这不会导致问题)。
经过一些初步设置后,我尝试使用removeFromSuperview()
调用删除此视图,但它不会被删除。
我正在主要调度,因为我正在后台线程中进行此删除调用。
以下是相关代码:
将视图添加到keyWindow
fileprivate func addOverlapView() {
let frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
self.overlapView = UIView(frame: frame)
let overlapGradient: CAGradientLayer = CAGradientLayer()
overlapGradient.colors = [self.fromColor.cgColor, self.toColor.cgColor]
overlapGradient.locations = [0.0, 1.0]
overlapGradient.frame = self.view.bounds
overlapGradient.masksToBounds = true
overlapView.layer.insertSublayer(overlapGradient, at: 0)
let textLabel = UILabel()
textLabel.text = "Configuring user settings"
textLabel.textAlignment = .center
textLabel.textColor = .white
overlapView.addSubview(textLabel)
textLabel.anchor(top: nil, left: nil, bottom: nil, right: nil, paddingTop: 0, paddinfLeft: 0, paddingBottom: 0, paddingRight: 0, width: overlapView.frame.width, height: 100)
textLabel.centerXAnchor.constraint(equalTo: overlapView.centerXAnchor).isActive = true
textLabel.centerYAnchor.constraint(equalTo: overlapView.centerYAnchor).isActive = true
UIApplication.shared.keyWindow?.addSubview(overlapView)
}
然后我尝试使用以下调用删除它:
DispatchQueue.main.async {
self.overlapView.removeFromSuperview()
}
但不知怎的,这个观点并没有被删除。
对可能导致此问题的任何暗示?