使用CAShapeLayer绘制点并不总是按照定义的比例

时间:2016-03-10 12:17:51

标签: objective-c core-graphics cashapelayer cgpoint

我绘制点并且我希望接收具有恒定宽度的线但有时点的宽度像梯形几何体一样扩展。 这是我的代码:

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreGraphics/CoreGraphics.h>

CAShapeLayer *_leftStrokeLayer;
CGMutablePathRef _leftstrokePath;

- (void)SetUpStrokeLayer
{

  _leftStrokeLayer = [CAShapeLayer layer];
  _leftStrokeLayer.strokeColor = [UIColor blueColor].CGColor;
  _leftStrokeLayer.lineWidth = 6.0f;
  _leftStrokeLayer.lineCap = @"round";
  _leftStrokeLayer.frame = self.bounds;
  _leftStrokeLayer.strokeColor = [UIColor blackColor].CGColor;
  _leftStrokeLayer.fillColor = [UIColor clearColor].CGColor;

  [self.layer insertSublayer:_leftStrokeLayer above:_imageView.layer];
}


- (void)drawPoint:(CGPoint)leftPoint
{
 if (_leftstrokePath == nil)
    {
            _leftStrokeLayer.path = nil;

            _leftstrokePath = CGPathCreateMutable();
            CGPathMoveToPoint(_leftstrokePath, nil, leftPoint.x, leftPoint.y);
    }

     CGPathAddLineToPoint(_leftstrokePath, nil, leftPoint.x, leftPoint.y);
     CGPathMoveToPoint(_leftstrokePath, nil, leftPoint.x, leftPoint.y);
     _leftStrokeLayer.path = _leftstrokePath;
}


- (void)clearLeftStrokePath
{
  if (_leftstrokePath)
  {
      CGPathRelease(_leftstrokePath);
  }
  _leftstrokePath = nil;
  _leftStrokeLayer.path = nil;
}

这就是我想要的:

good line another good line

有时我得到这个:

bad line another bad line

0 个答案:

没有答案