来自iOS的警告“请勿将子视图直接添加到视觉效果视图本身" [英] Warning from iOS "Do not add subviews directly to the visual effect view itself"
本文介绍了来自iOS的警告“请勿将子视图直接添加到视觉效果视图本身"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面有一个函数,当我链接到iOS 11 SDK时,出现错误:
I have a function below and when I link with the iOS 11 SDK, I get an error:
请勿将子视图直接添加到视觉效果视图本身,而应将其添加到-contentView.
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
?我想保持效果.
but the effect is not present that way. How can I keep using UIVisualEffectView
instead of UIView
? I want to keep the effect.
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)
}
推荐答案
只需遵循错误提示,然后将子视图添加到UIVisualEffectView
的contentView
.
Just follow what the error says and add your subviews to UIVisualEffectView
's contentView
.
effectView.contentView.addSubview(activityIndicator)
effectView.contentView.addSubview(strLabel)
这篇关于来自iOS的警告“请勿将子视图直接添加到视觉效果视图本身"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文