我有一个NSView
连接到自定义类。
该视图上有一些图画:
class LineDrawer: NSView {
var linear = NSBezierPath()
var storage = NSUserDefaults.standardUserDefaults()
override func drawRect(dirtyRect: NSRect) {
var color = NSColor()
if let newLoadedData = storage.objectForKey("color") as? NSData {
if let currentColor = NSUnarchiver.unarchiveObjectWithData(newLoadedData) as? NSColor {
color = currentColor
}
}
color.set()
linear.lineWidth = CGFloat(storage.integerForKey("width"))
linear.stroke()
}
override func mouseDown(theEvent: NSEvent) {
super.mouseDown(theEvent)
let location = theEvent.locationInWindow
var lastPt = theEvent.locationInWindow
lastPt.y -= frame.origin.y
linear.moveToPoint(lastPt)
}
override func mouseDragged(theEvent: NSEvent) {
super.mouseDragged(theEvent)
var newPt = theEvent.locationInWindow
newPt.y -= frame.origin.y
linear.lineToPoint(newPt)
needsDisplay = true
}
}
现在我需要编写一个函数来完全清除该视图。
不太清楚完全清晰的视图是什么意思,但你不能用纯色填充它吗?
[[NSColor windowBackgroundColor] setFill];
NSRectFill(self.bounds);
(还没有跟上 Swift 的热度)
update我提高了我的迅捷能力,看哪!
NSColor.windowBackgroundColor().setFill()
NSRectFill(self.bounds)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)