我有以下功能和警告,當我跟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)
}