UIBezierPath moved half aside

久未见 提交于 2019-12-25 01:43:39

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!