gpt4 book ai didi

iphone - 图层阴影的不透明度

转载 作者:行者123 更新时间:2023-12-03 20:53:58 25 4
gpt4 key购买 nike

我向 UIView 添加阴影:

[blurView.layer setCornerRadius:kCornerRadius];    
blurView.layer.masksToBounds = NO;
blurView.layer.shadowColor = [[UIColor redColor] CGColor];
blurView.layer.backgroundColor = blurView.layer.shadowColor;
blurView.layer.shadowPath = [UIBezierPath
bezierPathWithRoundedRect:CGRectMake(-2.0*kCornerRadius, -2.0*kCornerRadius, blurView.bounds.size.width+4.0*kCornerRadius, blurView.bounds.size.height+4.0*kCornerRadius)
cornerRadius:kCornerRadius].CGPath;
blurView.layer.cornerRadius = kCornerRadius;
blurView.layer.shadowOffset = CGSizeMake(0.0, 0.0);
blurView.layer.shadowRadius = kCornerRadius;
blurView.layer.shadowOpacity = kOpacity;
blurView.layer.opacity = 1.0;

这部分代码给了我一个这样的 View ,就像 uiview 被模糊一样:

enter image description here

当我尝试更改blurView.layer的不透明度(例如更改为0.5)时,我得到了意想不到的 View :

enter image description here

如你所见 - 我得到了 uiview 的锐利边缘。

我认为,阴影不透明度是图层不透明度的一部分 - 这是导致此“错误”的原因。有人能帮我解决这个问题吗?也许我可以在更改blurView.layer的不透明度或类似的东西之前合并图层吗?

UPD

通过此修复: BluView.layer.shadowColor = [[UIColor colorWithRed:1 绿色:0 蓝色:0 alpha:0.5] CGColor];

我明白了:

enter image description here

UPD

答案是使用 setShouldRasterize 方法:

enter image description here

谢谢大家!

[blurView.layer setShouldRasterize:YES];

最佳答案

答案是使用以下代码行:

blurView.layer.shouldRasterize = YES;

关于iphone - 图层阴影的不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6652562/

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