我有以下功能和警告,当我跟iOS 11 SDK链接,我得到一个错误:从iOS版“不要直接子视图添加到视觉效果视图本身”
Do not add subviews directly to the visual effect view itself, instead add them to the -contentView.
问题就可以通过改变
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))"
解决了
effectView = UIView()
但效果不存在这样的。我如何继续使用UIVisualEffectView
而不是UIView
?我想保持效果。
let imagePicker = UIImagePickerController()
let messageFrame = UIView()
var activityIndicator = UIActivityIndicatorView()
var strLabel = UILabel()
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
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: UIFont.Weight.medium)
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)
}