我想创建一个带有模糊和约束的UIImageView。但模糊不想使用约束。
我的代码:
var notifBackground: UIImageView!
notifBackground = UIImageView()
notifBackground.backgroundColor = UIColor.clear
view.addSubview(notifBackground)
notifBackground.translatesAutoresizingMaskIntoConstraints = false
notifBackground.widthAnchor.constraint(equalToConstant: 200).isActive = true
notifBackground.heightAnchor.constraint(equalToConstant: 200).isActive = true
notifBackground.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
notifBackground.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
let blur = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.regular))
blur.frame = notifBackground.bounds
view.addSubview(blur)
答案 0 :(得分:0)
当您将模糊的边界设置为imageview的相同边界时,尚未处理布局约束。 你要做的就是为模糊设置类似的约束。通过这样做,模糊将具有类似的边界并出现在图像视图的顶部。
答案 1 :(得分:0)
BLUR EFFECT
let blur = UIBlurEffect(style: UIBlurEffectStyle.regular)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = view.bounds
blurView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurView)