ios - UIBlurEffect 不会模糊 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
}
推荐阅读
- html - 需要将代码段链接到 url
- npm - Husky 安装失败无法读取 null 的“toString”属性
- python - 无法理解常量训练,使用 hashlib 进行测试拆分
- maven - 如何打包多模块maven项目?
- opencv - Flask 应用程序在本地服务器上工作,但不在全球范围内
- bash - 在公司网络中检查并设置 .zshrc/.bashrc 中的 http(s)_proxy
- ios - 如何从 ViewController swift 获取 CoreData 属性
- javascript - 使用两个数组特定数据和值创建新数组
- css - 应用 TranslateY 时,Firefox 以不同方式呈现元素
- java - 为什么选择数组列表
可以分配给 ArrayList