UIBezierPath 移到一边 [英] UIBezierPath moved half aside

查看:38
本文介绍了UIBezierPath 移到一边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试沿着 UIBezierPath 绘制视图.奇怪的是,它以视图的 50% 的偏移量开始.

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.

这是我的代码:

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?

谢谢

我添加了对 layoutSubview 的调用,并将偏移量从 x 移动到 y:

I've added a call to layoutSubview and it moved the offset from x to y:

推荐答案

好吧,我的错误是,我认为 UIBezierPath 描述了绘图的边缘.相反,它描述了中心.所以我将代码更改为:

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)))

它有效

这篇关于UIBezierPath 移到一边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆