标签: cgpath

CGMutablePathRef中的巨大内存泄漏

我在地图中渲染了近1000个多边形.我使用了多边形的路径

-   (CGPathRef)polyPath:(MKPolygon *)polygon
{
     MKMapPoint *points = [polygon points];
     NSUInteger pointCount = [polygon pointCount];
     NSUInteger i;
     if (pointCount < 3)
         return NULL;
     CGMutablePathRef path = CGPathCreateMutable();
     if([polygon isKindOfClass:[MKPolygon class]])
     {
            for (MKPolygon *interiorPolygon in polygon.interiorPolygons)
      {
       CGPathRef interiorPath = [self polyPath:interiorPolygon];
       CGPathAddPath(path, NULL, interiorPath);
       CGPathRelease(interiorPath);
       }
  }
     CGPoint relativePoint = [self pointForMapPoint:points[0]];
     CGPathMoveToPoint(path, NULL, relativePoint.x, relativePoint.y);
     for (i = 1; i < pointCount; i++) 
     {
            relativePoint = [self pointForMapPoint:points[i]];
            CGPathAddLineToPoint(path, NULL, relativePoint.x, relativePoint.y);
     }
     return path;
}

- (void)drawMapRect:(MKMapRect)mapRect …
Run Code Online (Sandbox Code Playgroud)

iphone core-foundation cgpath

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

调整UIView大小以适合CGPath

我有一个UIView子类,用户可以在其上添加随机CGPath.通过处理UIPanGestures添加CGPath.

我想将UIView调整为包含CGPath的最小矩形.在我的UIView子类中,我重写了sizeThatFits以返回最小尺寸:

- (CGSize) sizeThatFits:(CGSize)size {
    CGRect box = CGPathGetBoundingBox(sigPath);
    return box.size;
}
Run Code Online (Sandbox Code Playgroud)

这按预期工作,并且UIView的大小调整为返回的值,但CGPath也按比例"调整大小",从而产生与用户最初绘制的路径不同的路径.例如,这是用户绘制的路径视图:

绘制的路径

这是调整大小后的路径视图:

在此输入图像描述

如何调整我的UIView大小而不是"调整"路径?

uiview cgpath ios

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

移动CGPathCreateMutable()以使路径保持不变?

我在屏幕上有9个六角形精灵,我必须在它们周围指定一条特定的路径才能使它们的区域可触摸.我不想分别为每条路径设置坐标,所以我不能只使用第一条路径(六边形大小都相同)并将其原点移动到另一个位置(不破坏形状)?(如果我现在这样做,CGPathAddLineToPoint();会从前六边形中添加六边形的点.我希望我能得到这个想法......(见图片......注意:右上方的灰色八边形是与黑色完全相同的尺寸和形状)![移动路径坐标和形状] [1]

hex2TouchArea = CGPathCreateMutable();

    CGPathMoveToPoint(hex2TouchArea, NULL, 150,157);
    CGPathAddLineToPoint(hex2TouchArea, NULL, 130, 198);
    CGPathAddLineToPoint(hex2TouchArea, NULL, 146, 236);
    CGPathAddLineToPoint(hex2TouchArea, NULL, 195, 236);
    CGPathAddLineToPoint(hex2TouchArea, NULL, 218, 197);
    CGPathAddLineToPoint(hex2TouchArea, NULL, 193, 157);
    CGPathCloseSubpath(hex2TouchArea);
Run Code Online (Sandbox Code Playgroud)

在这里我把图片显示在图像中
http://666kb.com/i/bz2ysevuw8n65rh3i.gif

*编辑:我从帖子中得到了解决方案并稍微改了一下:*

-(CGMutablePathRef) drawHexagon:(CGPoint)origin
{
    //create mutable path
    CGMutablePathRef path = CGPathCreateMutable();

    CGPathMoveToPoint(path, nil, origin.x, origin.y);

    CGPoint newloc = CGPointMake(origin.x - 20, origin.y + 42);
    CGPathMoveToPoint(path, NULL, newloc.x, newloc.y);
    CGPathAddLineToPoint(path, NULL, newloc.x + 16,newloc.y + 38);
    CGPathAddLineToPoint(path, NULL, newloc.x + 49, newloc.y + 0);
    CGPathAddLineToPoint(path, NULL, newloc.x + 23, …
Run Code Online (Sandbox Code Playgroud)

objective-c cgpath

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

作为一个整体加入了UIBezierPath笔划

作为iOS绘图的初学者,我想绘制一个小工具提示容器,它由一个带指示箭头的矩形组成.我创建了2个UIBezierPaths并使用"appendPath"加入它们.我认为这是解决这个问题的正确方法,但经过一天的努力,我不得不寻求帮助.这是我现在的截图:

UIBezierPath的屏幕截图

正如您所看到的,问题很简单,当我尝试描边连接路径时,它不会作为一个整体被描边,而是作为单独的部分.也许有人可以指出我正确的方向来解决这个问题?

这是代码:

    // Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // create indicator path
    UIBezierPath *indicator = [[UIBezierPath alloc] init];
    // corner radius
    CGFloat radius = self.cornerRadius;
    // main path
    UIBezierPath *path;
    // format frame
    rect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height - self.indicatorSize.height);
    // assign path
    path = [UIBezierPath bezierPathWithRoundedRect: rect
                                 byRoundingCorners:UIRectCornerAllCorners
                                       cornerRadii:CGSizeMake(radius, radius)];
    // x point
    CGFloat x = (rect.size.width - self.indicatorSize.width) / 2;

    [indicator …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c cgpath ios uibezierpath

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

SpriteNode不遵循cgpath

我对新游戏精灵有问题......我的"汽车"在第一圈完美地跟踪了赛道,但从那时起它似乎在每一圈结束时都有偏差.有人能告诉我我做错了什么吗?

- (void)createSceneContents{
    self.backgroundColor = [SKColor blackColor];
    self.scaleMode = SKSceneScaleModeAspectFit;

    // CREATING THE CAR AND THE TRACK
    SKSpriteNode *myCar = [self newcar];
    myCar.position = [[self trackShape] position];;
    [self addChild:myCar];

    SKShapeNode *track = [self trackShape];
    track.position = CGPointMake(48, 40);
    [self addChild:track];
}



- (SKSpriteNode *)newcar{
    // GENERATES A RECTANGLE FOR THE SPRITE NODE
    SKSpriteNode *hull = [[SKSpriteNode alloc] initWithColor:[SKColor grayColor] size:CGSizeMake(20,50)];
    CGPathRef pathRef = [[self bPath] CGPath];
    // CAR SHOULD FOLLOW THE TRACK
    // OK ONLY ON THE FIRST LAP
    SKAction …
Run Code Online (Sandbox Code Playgroud)

cgpath ios7 sprite-kit skspritenode

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

如何创建一个随机闭合的平滑CGPath?

我试图找到一种方法来创建一个随机的闭合平滑路径(CGPathUIBezierPath).我已经阅读了关于De Casteljau的算法以及关于Bezier路径的其他文章,但它似乎不适合我试图实现的目标.

我想过创建一个CGPath圆圈.然后我会通过一个函数来增加路径,这个函数会扭曲点的位置,比如正弦或余弦.但是我不知道这是否是正确的方向,因为路径不会有随机的形状.

CGMutablePathRef circle = CGPathCreateMutable();
CGPathAddArc(circle, nil, 0.0f, 0.0f, 100.0f, 2 * M_PI, 0.0f, true);
...
CGPathRelease(circle);
Run Code Online (Sandbox Code Playgroud)

如果有人能指出我正确的方向如何开始实施它将是伟大的.我尝试生成的路径示例:

在此输入图像描述

cocoa-touch objective-c cgpath ios uibezierpath

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

使用SKShapeNode在Sprite Kit中绘制虚线

我提供了这个解决方案,但我不能把它变成快速的代码

这就是我的尝试

var pattern[2]:CGFloat; this 

var dashed: CGPathRef = CGPathCreateCopyByDashingPath(CGPathCreateCopyByDashingPath(path, transform, phase, lengths, count);

var myShapeNode: SKShapeNode!;

        var CGPathCreateCopyByDashingPath:CGPathRef;
Run Code Online (Sandbox Code Playgroud)

cgpath sprite-kit skshapenode swift

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

CGMutablePath.addArc在Swift 3中不起作用?

在Xcode 8 beta 6中,添加路径的一些函数发生了变化,包括添加弧的函数:

func addArc(center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool, transform: CGAffineTransform = default)
Run Code Online (Sandbox Code Playgroud)

除了函数的定义之外,Apple的网站上没有文档.我一直无法从这个函数得到一个实际的弧,并且一直依赖于使用切线的第二个版本.任何人都可以提供工作样品吗?可能只是被窃听?

这是一个由变化打破的功能:

public class func createHorizontalArcPath(_ startPoint:CGPoint, width:CGFloat, arcHeight:CGFloat, closed:Bool = false) -> CGMutablePath
    {
        // http://www.raywenderlich.com/33193/core-graphics-tutorial-arcs-and-paths

        let arcRect = CGRect(x: startPoint.x, y: startPoint.y-arcHeight, width: width, height: arcHeight)

        let arcRadius = (arcRect.size.height/2) + (pow(arcRect.size.width, 2) / (8*arcRect.size.height));
        let arcCenter = CGPoint(x: arcRect.origin.x + arcRect.size.width/2, y: arcRect.origin.y + arcRadius);

        let angle = acos(arcRect.size.width / (2*arcRadius));
        let startAngle = CGFloat(M_PI)+angle // (180 degrees …
Run Code Online (Sandbox Code Playgroud)

xcode cgpath ios swift

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

CGPathCreateCopyByTransformingPath到Swift 3

我是Swift 3的新手,我正在尝试将该函数转换为Swift 3:

- (void) drawRect: (CGRect)rect
{
    if (self.editionMode == Zoom) {

        for (Area *area in self.mArrayPaths) {

            CGAffineTransform zoom = CGAffineTransformMakeScale(self.scale, self.scale);

            CGPathRef movedPath = CGPathCreateCopyByTransformingPath([area.pathArea CGPath],                                                         &zoom);
            area.pathAreaTransformed = [UIBezierPath bezierPathWithCGPath:movedPath];


            [area.fillColor setFill];
            [area.strokeColor setStroke];

            [area.pathAreaTransformed fill];
            [area.pathAreaTransformed stroke];
        }
    }
    else if (self.editionMode == MoveShapes) {

        [self.currentArea.fillColor setFill];
        [self.currentArea.pathAreaShift fill];
        [self.currentArea.pathAreaShift stroke];

        for (Area *area in self.mArrayPaths) {

            if (area == self.currentArea) {

                continue;
            }

            [area.fillColor setFill];
            [area.strokeColor setStroke];

            [area.pathArea fill];
            [area.pathArea stroke];
        }

    } else …
Run Code Online (Sandbox Code Playgroud)

objective-c cgpath ios swift swift3

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

如何从UIView中删除CAShapeLayer和CABasicAnimation?

这是我的代码:

@objc func drawForm() {
    i = Int(arc4random_uniform(UInt32(formNames.count)))
    var drawPath = actualFormNamesFromFormClass[i]
    shapeLayer.fillColor = UIColor.clear.cgColor
    shapeLayer.strokeColor = UIColor.black.cgColor
    shapeLayer.lineWidth = 6
    shapeLayer.frame = CGRect(x: -115, y: 280, width: 350, height: 350)

    var paths: [UIBezierPath] = drawPath()
    let shapeBounds = shapeLayer.bounds
    let mirror = CGAffineTransform(scaleX: 1,
                                   y: -1)
    let translate = CGAffineTransform(translationX: 0,
                                      y: shapeBounds.size.height)
    let concatenated = mirror.concatenating(translate)

    for path in paths {
        path.apply(concatenated)
    }

    guard let path = paths.first else {
        return
    }

    paths.dropFirst()
        .forEach {
            path.append($0)
    }

    shapeLayer.transform …
Run Code Online (Sandbox Code Playgroud)

cabasicanimation cashapelayer cgpath swift swift-playground

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