1

使用我的应用程序时,我遇到了一些绘图问题:

我想知道为什么,回到 Obj-c,-moveToPoint()并且-lineToPoint()毫无问题地绘制所有内容,现在,使用 swift,除了出现在我的视图上的奇怪边框之外,一切似乎都一样。让我更好地解释一下:

想象一下,你的任务是画一条从 A(0,0) 到 B(10,10) 的基本线

我们都知道如何在 obj-c 中做到这一点,但在 swift 中我发现了一些新东西:

    var path : NSBezierPath = NSBezierPath(rect: dirtyRect)
    let color = NSColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
    color.set()
    path.moveToPoint(NSPoint(x: 0,y: 0))
    path.lineToPoint(NSPoint(x: 10,y: 10))
    path.lineWidth = 5.0 //Makes the line 5px width, but it even
                         //creates an annoying border along the view
                         //Try it out, i can't figure out how to get rid of it
    path.stroke()
4

2 回答 2

5

您正在使用矩形初始化贝塞尔路径,因此该矩形是在您调用 path.stroke() 时被描边的路径的一部分。您可以将路径初始化为 NSBezierPath()。

于 2014-06-20T00:22:51.597 回答
-3

我建议,您应该分别使用更新后的 、和,而不是使用NSBezierPath、和。NSColorNSPointUIBezierPathUIColorCGPoint

于 2014-06-19T20:56:23.150 回答