标签: cgpath

CGPath掩盖了CGPoints

我正在努力建立这个: 在此输入图像描述

白色背景实际上是透明的.我知道如何将CGPath剪辑到一个设置区域,但这似乎是以其他方式,因为我需要从填充的CGPath中减去区域.

我想正确的方法是从CGPath中减去整个外圈,然后在我的CGPoints中绘制较小的圆圈,但我不知道如何执行前者.谁能指出我正确的方向?

iphone core-graphics cgpath

4
推荐指数
1
解决办法
932
查看次数

来自字符串的CGPathRef

请怎样才能得到法国信的特定阿拉伯语的路径?我刚刚发现CTFontCreatePathForGlyph会给CGPathRef,但它将是文本的轮廓.

我需要这个真正的文本路径来显示文本绘制动画..

请帮忙

iphone objective-c cgpath core-text ios

4
推荐指数
2
解决办法
3458
查看次数

如何在不创建新CGPath的情况下移动CGPath

我正在创建一个CGPath在我的游戏中定义一个区域,如下所示:

CGPathMoveToPoint   ( myPath, NULL, center.x, center.y );
CGPathAddLineToPoint( myPath, NULL,center.x + 100, center.y);
CGPathAddLineToPoint( myPath, NULL, center.x + 100, center.y + 100);
CGPathAddLineToPoint( myPath, NULL, center.x,  center.y + 100);
CGPathCloseSubpath  ( myPath );
Run Code Online (Sandbox Code Playgroud)

我知道这只是一个正方形,我可以使用另一个,CGRect但我希望实际创建的路径实际上并不是一个矩形(我现在只是测试).然后简单地用以下方法检测触摸区域:

if (CGPathContainsPoint(myPath, nil, location, YES))
Run Code Online (Sandbox Code Playgroud)

这一切都很好,问题是CGPath可能每秒最多移动40次.如何在不创建新的情况下移动它?我知道我可以做这样的事情来"移动"它:

center.y += x;
CGPathRelease(myPath);
myPath = CGPathCreateMutable();
CGPathMoveToPoint   ( myPath, NULL, center.x, center.y );
CGPathAddLineToPoint( myPath, NULL,center.x + 100, center.y);
CGPathAddLineToPoint( myPath, NULL, center.x + 100, center.y + 100);
CGPathAddLineToPoint( myPath, NULL, center.x, …
Run Code Online (Sandbox Code Playgroud)

iphone core-graphics cgpath

3
推荐指数
1
解决办法
6479
查看次数

对UIBezierPath + applyTransform + CGPath感到困惑

我在x和y方向上按比例2缩放UIBezierPath(由一个[0,0 - 1x1] rect构建).UIBezierPath".bounds"没问题(即按预期缩放),而".CGPath"保持不变......

码:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0,
                                                                     1, 1)];
    NSLog(@"path.bounds box before transform:%@",
          NSStringFromCGRect(path.bounds));
    NSLog(@"path.CGPath box before transform:%@",
          NSStringFromCGRect(CGPathGetBoundingBox(path.CGPath)));

    [path applyTransform:CGAffineTransformMakeScale(2, 2)];

    NSLog(@"path.bounds box after transform:%@",
          NSStringFromCGRect(path.bounds));
    NSLog(@"path.CGPath box after transform:%@",
          NSStringFromCGRect(CGPathGetBoundingBox(path.CGPath)));

    return 0;        
}
Run Code Online (Sandbox Code Playgroud)

输出:

path.bounds box before transform:{{0, 0}, {1, 1}}
path.CGPath box before transform:{{0, 0}, {1, 1}}
path.bounds box after transform:{{0, 0}, {2, 2}}
path.CGPath box after transform:{{0, 0}, {1, 1}}
Run Code Online (Sandbox Code Playgroud)

为什么?

core-graphics cgpath ios uibezierpath

3
推荐指数
1
解决办法
5134
查看次数

如何使用CGPathAddCurveToPoint创建一个完美的半圈?

我试图用CGPathAddCurveToPoint创建一个15点半径的完美右半圆,如下所示:

CGPathMoveToPoint(path, NULL, 0, 0);
CGPathAddCurveToPoint(path, NULL, 15, 0, 15, 30, 0, 30);
Run Code Online (Sandbox Code Playgroud)

它从圆圈的中间开始.然后将第一个控制点设置为圆的边界框的右上角.第二个控制点设置在圆的边界框的右下角.圆圈终止于边界框的底部中间.

但绘制时,圆圈呈鸡蛋状.

我怎样才能从0,0点向右开始到0,30结束,形成一个完美无瑕的右半球?

iphone core-graphics cgpath ipad ios

3
推荐指数
1
解决办法
4169
查看次数

如何到达CGPath进行命中测试?

我有一个开放的CGPath/UIBezierPath,如果用户触摸它,我想检测它,即一个点是否在距路径一定距离内.路径是开放的(即线/曲线,而不是形状).它可以包含直线和弯曲元素.如何到达测试路径的距离?

core-graphics objective-c cgpath

3
推荐指数
1
解决办法
1001
查看次数

如何创建Swift的波形路径

我希望我的节点以正弦曲线波形运行,我尝试将其用于CGPath.如何创建遵循正弦曲线的CGPath?除了手动找到曲线上的点之外还有其他方法,还是我可以传入正弦函数?

let action = SKAction.followPath(<the sine path>, asOffset: true, orientToPath: true, duration: 5)

这可以通过Bezier Paths完成,然后转换成CGPaths吗?谢谢.

trigonometry cgpath sprite-kit swift2

3
推荐指数
1
解决办法
1176
查看次数

获取UIBezierPath Stroke的大纲路径

我有一个UIBezierPath中风,现在我想得到笔画的轮廓路径(不是笔画的路径本身),有没有办法可以得到它?或者至少NSLogUIBezierPath笔画的轮廓路径?谢谢

objective-c cgpath ios uibezierpath

3
推荐指数
1
解决办法
546
查看次数

将非转义值转换为 'T' 可能允许它转义 Xcode 10 Swift CGPath

我有这段代码,它在 Xcode 9 中运行良好,但在 Xcode 10 中我收到了这个错误。将非转义值转换为 'T' 可能允许它转义

这是代码:

extension CGPath {

    func forEach( body: @convention(block) (CGPathElement) -> Void) {
        typealias Body = @convention(block) (CGPathElement) -> Void
        let callback: @convention(c) (UnsafeMutableRawPointer, UnsafePointer<CGPathElement>) -> Void = { (info, element) in
            let body = unsafeBitCast(info, to: Body.self)
            body(element.pointee)
        }
        print(MemoryLayout.size(ofValue: body))
        let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
        self.apply(info: unsafeBody, function: unsafeBitCast(callback, to: CGPathApplierFunction.self))
    }
Run Code Online (Sandbox Code Playgroud)

我收到此 2 行代码的错误

 print(MemoryLayout.size(ofValue: body))
            let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
Run Code Online (Sandbox Code Playgroud)

用于MemoryLayoutunsafeBitCast

cgpath swift4 ios12 xcode10

3
推荐指数
1
解决办法
3113
查看次数

使用 UIImageView 在 UIView 中切透明孔

我正在尝试为我的 QR 相机视图创建下面的图像。

在此输入图像描述

我有一个相机覆盖图像(屏幕中间的正方形)。

我在 stackoverflow 上查看了类似的主题,并找到了如何从黑色背景(0.75% 透明)中剪切出相机覆盖图像,以便在中间留下空白空间,但是我在其放置方面遇到了一些实际问题,我不知道什么行为如此奇怪。

这是我用来创建背景黑色图像并剪掉中心正方形的代码:

            // Create a view filling the screen.
        let backgroundView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))

        // Set a semi-transparent, black background.
        backgroundView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.75)

        // Create the initial layer from the view bounds.
        let maskLayer = CAShapeLayer()
        maskLayer.frame = backgroundView.bounds
        maskLayer.fillColor = UIColor.black.cgColor

        // Create the path.
        let path = UIBezierPath(rect: backgroundView.bounds)
        maskLayer.fillRule = CAShapeLayerFillRule.evenOdd

        // Append the overlay image …
Run Code Online (Sandbox Code Playgroud)

uiimageview cgpath ios uibezierpath swift

3
推荐指数
1
解决办法
3053
查看次数