如何为一组CALayers添加阴影? 我有一个“FoldingView”类,它包含几个“SliceView”类。每个sliceview的图层都将被赋予一个CATransform3D,我正在使用透视属性(.m34 = 1.0 / -1000)。
如何添加具有良好视觉逻辑的阴影?这是我到目前为止所想的:
我可以获取每个切片的路径并将它们组合起来以获得阴影路径。
我可以将标准CALayer阴影应用于所有图层
如果有人有任何其他建议或知道如何编写1号创意,我将非常高兴!以下是您从屏幕截图中看到的示例项目的链接。
Download zipped application with code
答案 0 :(得分:1)
这似乎按照需要工作。这是根据sliceview完成的。
- (UIBezierPath *)shadowPath
{
if(self.progress == 0 && self.position != VGFoldSliceCenter)
{
UIBezierPath *path = [UIBezierPath bezierPath];
return path;
}
else
{
CGPoint topLeft = pointForAnchorPointInRect(CGPointMake(0, 0), self.bounds);
CGPoint topRight = pointForAnchorPointInRect(CGPointMake(1, 0), self.bounds);
CGPoint bottomLeft = pointForAnchorPointInRect(CGPointMake(0, 1), self.bounds);
CGPoint bottomRight = pointForAnchorPointInRect(CGPointMake(1, 1), self.bounds);
CGPoint topLeftTranslated = [self.superview convertPoint:topLeft fromView:self];
CGPoint topRightTranslated = [self.superview convertPoint:topRight fromView:self];
CGPoint bottomLeftTranslated = [self.superview convertPoint:bottomLeft fromView:self];
CGPoint bottomRightTranslated = [self.superview convertPoint:bottomRight fromView:self];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:topLeftTranslated];
[path addLineToPoint:topRightTranslated];
[path addLineToPoint:bottomRightTranslated];
[path addLineToPoint:bottomLeftTranslated];
[path closePath];
return path;
}
}