我绘制点并且我希望接收具有恒定宽度的线但有时点的宽度像梯形几何体一样扩展。 这是我的代码:
#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;
}
这就是我想要的:
有时我得到这个: