【发布时间】:2021-10-11 04:11:58
【问题描述】:
所以按钮 stackview 在另一个 ImageView 上具有模糊和透明的视图。我怎样才能使这项工作? 我尝试过模糊效果视图和视觉效果视图,但都未能实现这个设计。我也尝试使用 CIFilter 来模糊 StackView 的背景图像,但仍然不是同一个。
评论的答案,模糊效果和视觉视图的代码。实际效果见下图。
let test: UIView = {
let test = UIView()
test.backgroundColor = .clear
return test
}()
let blurEffect = UIBlurEffect(style: .extraLight)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.translatesAutoresizingMaskIntoConstraints = false
pictureImageView.insertSubview(blurView, at: 0)
blurView.snp.makeConstraints { (make) in
make.centerX.equalTo(view)
make.top.equalTo(view).offset(450)
make.width.equalTo(169)
make.height.equalTo(48)
}
let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
let vibrancyView = UIVisualEffectView(effect: vibrancyEffect)
vibrancyView.translatesAutoresizingMaskIntoConstraints = false
vibrancyView.contentView.addSubview(test)
blurView.contentView.addSubview(vibrancyView)
vibrancyView.snp.makeConstraints { (make) in
make.centerX.equalTo(view)
make.top.equalTo(view).offset(450)
make.width.equalTo(169)
make.height.equalTo(48)
}
更新,添加下面提到的alpha @Narjes 后,添加的唯一代码是blurView.alpha = 0.3,结果在这里,似乎缺少模糊效果。
【问题讨论】:
-
“我尝试过模糊效果视图和视觉效果视图,但都未能实现这个设计”在哪里?我们没有看到任何一行代码。
-
@ElTomato 添加
-
blurView.frame = CGRect(origin: CGPoint.zero, size: pictureImageView.frame.size)
标签: swift cifilter stackview uiblureffect