Swift和NSBezierPath

Alb*_*ini 1 cocoa nsbezierpath swift

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

我想知道为什么为什么要回到Obj-c -moveToPoint()-lineToPoint()没有问题地绘制所有东西,而现在却迅速地看到所有东西都一样,只是我的视线出现一个奇怪的边界。让我更好地解释一下:

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

我们都知道如何在obj-c中做到这一点,但是很快我就有了新的东西:

    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()
Run Code Online (Sandbox Code Playgroud)

小智 5

您正在使用rect初始化贝塞尔曲线路径,以便rect是调用path.stroke()时被描边的路径的一部分。您可以将路径初始化为NSBezierPath()。