问题
I'm trying to draw along an UIBezierPath to a view. The weird thing is, it starts with an offset of 50% of the view.
The grey part is the view and the lines are what I'm drawing.
Here is my code:
lineLayer.bounds = CGRectMake(0, 0, self.bounds.width, self.bounds.height);
lineLayer.strokeColor = UIColor.blackColor().CGColor
lineLayer.lineDashPattern = [3, 2, 1, 2, 1, 2, 1, 2, 1, 2]
lineLayer.lineWidth = lineLayer.bounds.height
var linePath = UIBezierPath()
linePath.moveToPoint(CGPointMake(0, CGRectGetMaxY(lineLayer.bounds)))
linePath.addLineToPoint(CGPointMake(CGRectGetMaxX(lineLayer.bounds), CGRectGetMaxY(lineLayer.bounds)))
lineLayer.path = linePath.CGPath;
Does anyone know what I'm doing wrong?
Thanks
EDIT: I've added a call to layoutSubview and it moved the offset from x to y:
回答1:
Okay my error was, that I thought the UIBezierPath describes the edge of the drawing. Instead it describes the center. So I've changed my code to:
linePath.moveToPoint(CGPointMake(0, CGRectGetMidY(lineLayer.bounds)))
linePath.addLineToPoint(CGPointMake(CGRectGetMaxX(lineLayer.bounds), CGRectGetMidY(lineLayer.bounds)))
and it works
来源:https://stackoverflow.com/questions/26828134/uibezierpath-moved-half-aside