Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 买一个CALayer';s";“屏蔽路径”;在非变换坐标系中_Macos_Cocoa_Core Animation_Calayer_Quartz Graphics - Fatal编程技术网

Macos 买一个CALayer';s";“屏蔽路径”;在非变换坐标系中

Macos 买一个CALayer';s";“屏蔽路径”;在非变换坐标系中,macos,cocoa,core-animation,calayer,quartz-graphics,Macos,Cocoa,Core Animation,Calayer,Quartz Graphics,在Mac上的CoreAnimation中,有没有一种方法可以获得一条贝塞尔路径,它本质上是CALayer的“实际像素边界”或“遮罩路径” 例如,我有一个CALayer,它的内容是一个照片集,一个1px的白色边框,以及一个X和Y旋转变换。有没有一种方法可以在应用变换的情况下导出其像素的路径 示例图像: 我找到了满足自己需要的方法。这不是真正的“掩码路径”,但它是参数层坐标空间中变换矩形的路径,这才是我真正需要的 此方法的上下文是CALayer上的一个类别: - (NSBezierPath*)lay

在Mac上的CoreAnimation中,有没有一种方法可以获得一条贝塞尔路径,它本质上是CALayer的“实际像素边界”或“遮罩路径”

例如,我有一个CALayer,它的内容是一个照片集,一个1px的白色边框,以及一个X和Y旋转变换。有没有一种方法可以在应用变换的情况下导出其像素的路径

示例图像:


我找到了满足自己需要的方法。这不是真正的“掩码路径”,但它是参数层坐标空间中变换矩形的路径,这才是我真正需要的

此方法的上下文是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;
}