UIBlurEffect 不会模糊 UITableViewCell 中的整个图像
UIBlurEffect not blurring entire image in UITableViewCell
我有以下代码来模糊图像。
let blurEffect = UIBlurEffect(style: .light)
let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.frame = imageBlur.bounds
//blurredEffectView.alpha = 0.8
imageBlur.addSubview(blurredEffectView)
imageBlur.sd_setImage(with: URL(string: item._galleryURL), placeholderImage: UIImage(named: ""))
但是,当我 运行 代码时,我在 UITableView 的前两个元素中看到了这一点。
当我向下滚动然后再次返回时,他们会修复...
什么可能导致此错误?
当您在 tableView 单元格中创建模糊视图时,您的视图现在不是准确大小。所以在第一次创建屏幕时它看起来不太好但是当你向下和向上滚动时它会回收并且知道它的大小它变得很好。
所以你可以通过在 layoutsubviews() 函数中给出大小来解决它,比如
override func layoutSubviews() {
super.layoutSubviews()
blurredEffectView.frame = imageBlur.bounds
}
我有以下代码来模糊图像。
let blurEffect = UIBlurEffect(style: .light)
let blurredEffectView = UIVisualEffectView(effect: blurEffect)
blurredEffectView.frame = imageBlur.bounds
//blurredEffectView.alpha = 0.8
imageBlur.addSubview(blurredEffectView)
imageBlur.sd_setImage(with: URL(string: item._galleryURL), placeholderImage: UIImage(named: ""))
但是,当我 运行 代码时,我在 UITableView 的前两个元素中看到了这一点。
当我向下滚动然后再次返回时,他们会修复...
什么可能导致此错误?
当您在 tableView 单元格中创建模糊视图时,您的视图现在不是准确大小。所以在第一次创建屏幕时它看起来不太好但是当你向下和向上滚动时它会回收并且知道它的大小它变得很好。
所以你可以通过在 layoutsubviews() 函数中给出大小来解决它,比如
override func layoutSubviews() {
super.layoutSubviews()
blurredEffectView.frame = imageBlur.bounds
}