标签: cgpath

获得CGPath总长度

我有许多UIBezierPath,我用CALyerAnimation @"StrokeStart"和@"strokeEnd"进行动画制作.

我希望动画对所有路径都具有相同的速度,所以我想我可以使用路径的长度:

距离/时间=速度

有没有办法计算路径"长度"?

谢谢

沙尼

cgpath ios uibezierpath

14
推荐指数
1
解决办法
5851
查看次数

Swift中CGPathApply的等效或替代?

预发布文档中,似乎没有Swift版本的CGPathApply.有没有等价物或替代品?我正在尝试获取CGPath的所有子路径,以便我可以从不同的起点重绘它.

cgpath swift

14
推荐指数
3
解决办法
4078
查看次数

如何用CGPath绘制多边形?

我一直在阅读文档但是我并不是立即清楚如何使用CGPath绘制多边形.我需要做的就是在这样的事情周围绘制CGPath:

__
\  \ 
 \  \
  \__\
Run Code Online (Sandbox Code Playgroud)

任何人都可以提供一个如何做到这一点的片段?

另外我假设CGPathContainsPoint将帮助我确定一个点是否在这样的路径中?或者路径是否必须是一个实体图

另外我怎么能移动cgpath?这就像在cgrect中更改像原点一样容易吗?

谢谢.

-Oscar

iphone core-graphics polygon draw cgpath

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

经常绘制CGPath时的性能

我正在开发一个将数据可视化为线图的iOS应用程序.该图表CGPath在全屏自定义中绘制UIView,最多包含320个数据点.数据经常更新,图表需要相应地重新绘制 - 刷新率为10 /秒会很好.

到目前为止这么容易.但是,我的方法似乎占用了大量的CPU时间.每秒10次刷新320个段的图形会导致iPhone 4S上的进程占CPU负载的45%.

也许我低估了引擎盖下的图形工作,但对我而言,CPU负载对于该任务似乎很重要.

下面是我的drawRect()函数,每次准备好一组新数据时都会调用它.N保持点的数量,并且points是具有CGPoint*要绘制的坐标的向量.

- (void)drawRect:(CGRect)rect {

    CGContextRef context = UIGraphicsGetCurrentContext();

    // set attributes
    CGContextSetStrokeColorWithColor(context, [UIColor lightGrayColor].CGColor);
    CGContextSetLineWidth(context, 1.f);

    // create path
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddLines(path, NULL, points, N+1);

    // stroke path
    CGContextAddPath(context, path);
    CGContextStrokePath(context);

    // clean up
    CGPathRelease(path); 
}
Run Code Online (Sandbox Code Playgroud)

我尝试首先将路径渲染到离线CGContext,然后按照此处的建议将其添加到当前层,但没有任何正面结果.我也直接向CALayer绘制了一个方法,但这也没有任何区别.

有关如何提高此任务性能的任何建议吗?或者渲染对我认识到的CPU更有用吗?OpenGL会有任何意义/差异吗?

谢谢/安迪

更新:我也尝试使用UIBezierPath而不是CGPath.这篇文章在这里给出了一个很好的解释为什么没有帮助.Tweaking CGContextSetMiterLimit等.也没有带来很大的解脱.

更新#2:我最终切换到OpenGL.这是一个陡峭而令人沮丧的学习曲线,但性能提升令人难以置信.但是,CoreGraphics的抗锯齿算法比OpenGL中的4x多重采样可以实现更好的工作.

core-graphics objective-c cgpath ios

13
推荐指数
2
解决办法
7316
查看次数

缩放CGPath以适应UIVIew

我需要知道如何缩小或缩小CGPath以便它可以适合UIView?

将背景颜色设置为黄色,以清楚地查看视图

self.frame = CGRectMake(0, 0, 181, 154);
self.backgroundColor = [UIColor yellowColor];
Run Code Online (Sandbox Code Playgroud)

绘制CAShapeLayer

CAShapeLayer *shape = [CAShapeLayer layer];
shape.path = aPath;

shape.strokeColor = [[UIColor blueColor] CGColor];
shape.lineWidth = 5;
shape.fillColor = [[UIColor clearColor] CGColor];

[self.layer addSublayer:shape];
Run Code Online (Sandbox Code Playgroud)

然后我得到这个: 在此输入图像描述

我想要的是这个: 在此输入图像描述

谢谢开发人员:)

core-graphics uiview cashapelayer cgpath ios

13
推荐指数
2
解决办法
7162
查看次数

将多个CGPath合并在一起以生成一个路径

我使用一些CGRects和Ellipses制作一个复杂的形状.一旦它被创建,我想要描述这条路径.当我抚摸路径时,它会抚摸每个形状.有没有办法可以将每个形状合并为一个路径,所以笔划不相交?

在此输入图像描述

int thirds = self.height / 3;

CGPathRef aPath = CGPathCreateMutable();

CGRect rectangle = CGRectMake((58 - 10) / 2, 46, 10, self.height - 58);
CGPathAddRect(aPath, nil, rectangle);

CGPathAddEllipseInRect(aPath, nil, CGRectMake((58 - 48) / 2, 0, 48, 48));
CGPathAddEllipseInRect(aPath, nil, CGRectMake((58 - 48) / 2, thirds, 48, 48));
CGPathAddEllipseInRect(aPath, nil, CGRectMake((58 - 48) / 2, thirds * 2, 48, 48));
CGPathAddEllipseInRect(aPath, nil, CGRectMake(0, self.height - 58, 58, 58));
CGPathCloseSubpath(aPath);
CGPathRef other = CGPathCreateCopy(aPath);

CAShapeLayer *square = [CAShapeLayer layer];
square.fillColor = [UIColor …
Run Code Online (Sandbox Code Playgroud)

objective-c cgpath

13
推荐指数
2
解决办法
8191
查看次数

CAShapeLayer的框架和界限

我在工作CAShapeLayer.而企图拉拢非线性path.I要设置框架CAShapeLayer.所以我可以使用CGPathGetPathBoundingBox的方法从得到的帧CGPathRef.

这是代码:

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100, (0), (M_PI_2), NO);
CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100-50, (M_PI_2), (0), YES);
CGPathCloseSubpath(path);
CAShapeLayer* arcLayer = [[CAShapeLayer alloc]init];
arcLayer.path = path;
arcLayer.frame = CGPathGetPathBoundingBox(path);
arcLayer.bounds = CGPathGetPathBoundingBox(path);
[self.layer addSublayer:arcLayer]; ` 
Run Code Online (Sandbox Code Playgroud)

请参考我的代码仔细.我已设置相同的框架和范围,以CAShapeLayer.My问题是,如果我没有设置界限(同帧),那么它不会显示我的内容或它不会显示内frame.Why我的内容?请帮助我.谢谢你.

cashapelayer cgpath ios

11
推荐指数
2
解决办法
1万
查看次数

如何正确使用CGPathApply

我正在尝试使用CGPathApply迭代CGPathRef对象中的每个CGPathElement(主要是为了编写一个自定义方式来保存CGPath数据).问题是,每次调用CGPathApply时,我的程序都会崩溃而根本没有任何信息.我怀疑问题在于应用程序功能,但我不知道.以下是我的代码示例:

- (IBAction) processPath:(id)sender {
 NSMutableArray *pathElements = [NSMutableArray arrayWithCapacity:1];
    // This contains an array of paths, drawn to this current view
 CFMutableArrayRef existingPaths = displayingView.pathArray;
 CFIndex pathCount = CFArrayGetCount(existingPaths);
 for( int i=0; i < pathCount; i++ ) {
  CGMutablePathRef pRef = (CGMutablePathRef) CFArrayGetValueAtIndex(existingPaths, i);
  CGPathApply(pRef, pathElements, processPathElement);
 }
}

void processPathElement(void* info, const CGPathElement* element) {
 NSLog(@"Type: %@ || Point: %@", element->type, element->points);
}
Run Code Online (Sandbox Code Playgroud)

关于为什么调用这个applier方法似乎崩溃的任何想法?任何帮助是极大的赞赏.

iphone quartz-graphics cgpath

10
推荐指数
1
解决办法
4997
查看次数

CGPathAddCurveToPoint的参数是什么意思?

我想CGPathRef在一天中的不同时刻基于太阳的坐标以编程方式构建.计算积分不是问题,但我想做一个CGPathRef平滑的想法CGPathAddCurveToPoint是合适的.

我理解路径,变换,x和y参数,但我不确定其他参数.根据Apple文档,它们是控制点,我猜它们就像你在矢量绘图程序中看到的那样,你可以调整曲线通过点的方式.

我的问题是如何在不知道这些坐标提前的情况下选择与我的坐标相关的点?我想也许只是从每个第一个控制点中减去一个设定的数量,并将相同的数量添加到第二个控制点,但这听起来过于简单.是否有一种标准方法可以生成对于平滑曲线"有意义"的控制点?

void CGPathAddCurveToPoint (
   CGMutablePathRef path,
   const CGAffineTransform *m,
   CGFloat cp1x,
   CGFloat cp1y,
   CGFloat cp2x,
   CGFloat cp2y,
   CGFloat x,
   CGFloat y
); 
Run Code Online (Sandbox Code Playgroud)

core-animation cgpath ios

10
推荐指数
1
解决办法
5817
查看次数

使用CGPathContainsPoint SWIFT的麻烦

我需要检查CGPoint是否在SKSpriteNode中.

经过一番研究,CGPathContainsPoint似乎是出于我的目的.

if CGPathContainsPoint(my_sprite_path, nil, my_point, false) {

 }
Run Code Online (Sandbox Code Playgroud)

但Xcode警告我:使用未解析的标识符CGPathContainsPoint

我试图导入:

import UIKit
import CoreGraphics
Run Code Online (Sandbox Code Playgroud)

我正在使用Xcode 8.0 beta 6.

我错过了什么吗?

cgpath sprite-kit skspritenode swift

10
推荐指数
1
解决办法
1813
查看次数