Warning from iOS “Do not add subviews directly to the visual effect view itself”

前端 未结 3 1869
春和景丽
春和景丽 2021-01-05 16:23

I have a function below and when I link with the iOS 11 SDK, I get an error:

Do not add subviews directly to the visual effect view itself, instead ad

3条回答
  •  走了就别回头了
    2021-01-05 17:04

    let messageFrame = UIView()
    var activityIndicator = UIActivityIndicatorView()
    var strLabel = UILabel()
    effectView = UIView()
    
       func activityIndicator(_ title: String) {
    
        strLabel.removeFromSuperview()
        activityIndicator.removeFromSuperview()
        effectView.removeFromSuperview()
    
        strLabel = UILabel(frame: CGRect(x: 50, y: 0, width: 160, height: 46))
        strLabel.text = title
        strLabel.font = UIFont.systemFont(ofSize: 14, weight: UIFontWeightMedium)
        strLabel.textColor = UIColor(white: 0.9, alpha: 0.7)
    
        effectView.frame = CGRect(x: view.frame.midX - strLabel.frame.width/2, y: view.frame.midY - strLabel.frame.height/2 , width: 160, height: 46)
        effectView.layer.cornerRadius = 15
        effectView.layer.masksToBounds = true
    
        activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .white)
        activityIndicator.frame = CGRect(x: 0, y: 0, width: 46, height: 46)
        activityIndicator.startAnimating()
    
        effectView.addSubview(activityIndicator)
        effectView.addSubview(strLabel)
        view.addSubview(effectView)
    }
    

    when start :

         activityIndicator("Your Text")
    

    when Finished :

        self.effectView.removeFromSuperview()
    

提交回复
热议问题