Opacity of layer's shadow
I add shadow to the 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;
This part of code gives me a this view, like a uiview is blured:
W开发者_开发问答hen I try change opacity of blurView.layer (for example to 0.5), I get unexpected view:
As you can see - I get a sharp edges of uiview.
I think, shadow opacity is a part of opacity of layer - it's a cause of this 'error'. Can anybody help me to fix this? May be can I merge layers before change opacity of blurView.layer or something like this?
UPD
With this fix: blurView.layer.shadowColor = [[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5] CGColor];
I get this:
UPD
Answer is using setShouldRasterize method:
Thanks everybody!
[blurView.layer setShouldRasterize:YES];
The answer is using this code line:
blurView.layer.shouldRasterize = YES;
Maybe you could try putting this in?
blurView.layer.shadowColor = [[UIColor colorWithRed:1 green:0 blue:0 alpha:0.5] CGColor];
What happens if you put this :
blurView.layer.shadowOpacity = 1.0;
blurView.layer.opacity = 0.5;
I think that you might be setting the shadow opacity to 0.5 and then the whole layer to 0.5, making the shadow twice as transparent?
(or I'm completely wrong!)
精彩评论