【问题标题】:How to add shadow to a group of CALayer using CATransform3D如何使用 CATransform3D 为一组 CALayer 添加阴影
【发布时间】:2012-08-11 14:05:05
【问题描述】:

如何为一组 CALayers 添加阴影? 我有一个“FoldingView”类,它维护几个“SliceView”类。每个 sliceview 的层都将被赋予一个 CATransform3D,其中我使用了透视属性 (.m34 = 1.0 / -1000)。

如何添加具有良好视觉逻辑的阴影?到目前为止,这是我一直在想的:

  1. 我可以获得每个切片的路径并将它们组合起来以获得阴影路径。

    • 不知道图层使用CATransform3D时如何获取CALayer的路径
    • 它可能在视觉上起作用,但如果光应该来自左上角,恐怕它不会完全正确。
  2. 我可以将标准的 CALayer 阴影应用到所有图层

    • 由于阴影相互重叠,看起来不太好

如果有人有任何其他建议或知道如何编写第 1 个想法,我将非常高兴!这是您从屏幕截图中看到的示例项目的链接。

Download zipped application with code

【问题讨论】:

  • 如果您要否决我的问题,请添加评论。我想知道这个问题有什么问题!

标签: objective-c ios calayer uibezierpath cgpath


【解决方案1】:

这似乎可以正常工作。这是按切片视图完成的。

- (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;
    } 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 2021-03-23
    • 1970-01-01
    相关资源
    最近更新 更多