gpt4 book ai didi

iOS10 UIView模糊效果带阴影

转载 作者:搜寻专家 更新时间:2023-10-31 19:29:20 24 4
gpt4 key购买 nike

如何在带阴影的UIView上做模糊效果?如果我这样做:

    override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
let layer = self.view.layer;
layer.shadowColor = UIColor.black.cgColor
layer.shadowOpacity = 1.0
layer.shadowOffset = CGSize(width: 0.0, height: 0.5)
layer.shadowRadius = 5.0

self.view.backgroundColor = UIColor.clear

let blurEffect = UIBlurEffect(style: .light)
let sideEffectView = UIVisualEffectView(effect: blurEffect)
sideEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

sideEffectView.frame = self.view.bounds;
self.view.addSubview(sideEffectView)
}

有阴影但没有模糊效果,如果我这样做:

    override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
self.view.backgroundColor = UIColor.clear

let blurEffect = UIBlurEffect(style: .light)
let sideEffectView = UIVisualEffectView(effect: blurEffect)
sideEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

sideEffectView.frame = self.view.bounds;
self.view.addSubview(sideEffectView)
}

有模糊效果但没有阴影。

感谢您的帮助!

最佳答案

感谢您的回答。我还找到了另一个解决方案。对于你的,它并不是真正的影子(没有半径......):

    override func viewDidLoad() {
super.viewDidLoad()

self.view.backgroundColor = UIColor.clear

let blurEffect = UIBlurEffect(style: .light)
let sideEffectView = UIVisualEffectView(effect: blurEffect)
sideEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

sideEffectView.frame = self.view.bounds
self.view.addSubview(sideEffectView)

let shadowView = UIView(frame: CGRect(x: 0.0, y: 0, width: self.view.bounds.size.width, height: self.view.bounds.size.height))
shadowView.translatesAutoresizingMaskIntoConstraints = false
shadowView.backgroundColor = UIColor.white
shadowView.layer.masksToBounds = false
shadowView.layer.shadowOffset = CGSize(width: 2.5, height: 2.5)
shadowView.layer.shadowOpacity = 1.0
shadowView.layer.shadowRadius = 2.5

self.view.insertSubview(shadowView, at: 0)

// Set constraints programmatically, as this view is animatable
NSLayoutConstraint(item: shadowView, attribute: NSLayoutAttribute.trailing, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.trailingMargin, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: shadowView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.topMargin, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: shadowView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.bottomMargin, multiplier: 1.0, constant: 0.0).isActive = true
NSLayoutConstraint(item: shadowView, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1.0, constant: 5.0).isActive = true
}

Blur effect with shadow

关于iOS10 UIView模糊效果带阴影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39513573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com