2016-08-31 36 views
1

我想使用此代码绘制在NSImageView铅笔条纹画在OSX铅笔条纹:使用SWIFT

class DrawView: NSImageView 
{ 
    var point = NSPoint() 
    override func drawRect(dirtyRect: NSRect) 
    { 
    let myContext = NSGraphicsContext.currentContext()?.CGContext 
    CGContextSetRGBStrokeColor (myContext, 1, 0, 0, 1) 
    CGContextAddArc(myContext, point.x, point.y,1,0.1,0,0) 
    CGContextSetLineWidth(myContext, 1) 
    CGContextStrokePath(myContext) 
    } 

    func MousePan(mouseLocation: NSPoint) 
    { 
    point = mouseLocation 
    self.setNeedsDisplay() 
    } 
} 

到目前为止,几乎所有的作品很好,我得到我的MousePointer一个红色的点作为只要我点击我的视图移动鼠标。 我的问题是,我没有看到我的观点的条纹,只是这个小红点。 我必须做些什么才能让这件事情起作用?

在此先感谢。

回答

0

首先,您应该使用NSView的子类,而不是NSImageView

而且这些方法有点儿缺乏。

它去更像是:

  • CGContextMoveToPoint
  • 然后CGContextLineToPointCGContextCurvedLineToPoint
  • 然后如果有必要CGContextClosePath
  • 然后CGContextStrokePath