【问题标题】:Get a CALayer's "mask path" in non-transformed coordinates在非转换坐标中获取 CALayer 的“蒙版路径”
【发布时间】:2014-02-16 23:19:39
【问题描述】:

在 Mac 上的 CoreAnimation 中是否有办法获得贝塞尔路径,该路径本质上是 CALayer 的“实际像素边界”或“蒙版路径”?

例如,我有这个 CALayer,其内容为照片集、1px 白色边框和 X 和 Y 旋转变换。有没有办法通过应用变换来导出其像素的路径?

示例图片:

【问题讨论】:

    标签: macos cocoa core-animation calayer quartz-graphics


    【解决方案1】:

    我想出了如何满足我的需要。这不是真正的“蒙版路径”,而是转换后的矩形在参数层坐标空间中的路径,这正是我所需要的。

    这个方法的上下文是CALayer上的一个类别:

    - (NSBezierPath*)layerPathConvertedToLayer:(CALayer*)toLayer
    {
        CGRect bounds = self.bounds;
        CGPoint topLeft = CGPointMake(NSMinX(bounds), NSMinY(bounds));
        CGPoint topRight = CGPointMake(NSMaxX(bounds), NSMinY(bounds));
        CGPoint bottomRight = CGPointMake(NSMaxX(bounds), NSMaxY(bounds));
        CGPoint bottomLeft = CGPointMake(NSMinX(bounds), NSMaxY(bounds));
    
        CGPoint convertedTopLeft = [self convertPoint:topLeft toLayer:toLayer];
        CGPoint convertedTopRight = [self convertPoint:topRight toLayer:toLayer];
        CGPoint convertedBottomRight = [self convertPoint:bottomRight toLayer:toLayer];
        CGPoint convertedBottomLeft = [self convertPoint:bottomLeft toLayer:toLayer];
    
        NSBezierPath *bezierPath = [NSBezierPath bezierPath];
        [bezierPath moveToPoint:convertedTopLeft];
        [bezierPath lineToPoint:convertedTopRight];
        [bezierPath lineToPoint:convertedBottomRight];
        [bezierPath lineToPoint:convertedBottomLeft];
        [bezierPath lineToPoint:convertedTopLeft];
        [bezierPath closePath];
    
        return bezierPath;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多