相关疑难解决方法(0)

为什么maskToBounds = YES会阻止CALayer阴影?

使用以下代码片段,我将向我的UIView添加阴影效果.哪个效果很好.但是只要我将视图的masksToBounds属性设置为YES即可.投影效果不再呈现.

self.myView.layer.shadowColor = [[UIColor blackColor] CGColor];
self.myView.layer.shadowOpacity = 1.0;
self.myView.layer.shadowRadius = 10.0;
self.myView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
self.myView.layer.cornerRadius = 5.0;
self.myView.layer.masksToBounds = YES; // <-- This is causing the Drop shadow to not be rendered
UIBezierPath *path = [UIBezierPath bezierPathWithCurvedShadowForRect:self.myView.bounds];
self.myView.layer.shadowPath = path.CGPath;
self.myView.layer.shouldRasterize = YES;
Run Code Online (Sandbox Code Playgroud)

你有什么想法吗?

objective-c calayer uiview ios

81
推荐指数
3
解决办法
5万
查看次数

标签 统计

calayer ×1

ios ×1

objective-c ×1

uiview ×1