我发现mouseDown被调用但不是mouseMoved。如何调用mouseMoved?这是我的代码:
@available(OSX 10.10, *)
class MainView: NSView{
override var acceptsFirstResponder: Bool { return true }
override func draw(_ dirtyRect: NSRect){
titledString.draw(at:NSPoint(x:20,y:40))
}
override func mouseDown(with event: NSEvent){
//print("Mouse down")
printMouseDown()
}
override func mouseMoved(with event: NSEvent){
//print("Mouse down")
super.mouseMoved(with:event)
printMouseMove()
}
}
这是什么?我怎么能修改代码
P.S。 这是驱动程序代码:
@available(OSX 10.10, *)
class AppDelegate: NSObject, NSApplicationDelegate {
let window = NSWindow()
func applicationDidFinishLaunching(_ notification: Notification){
window.setContentSize(NSSize(width:200, height:160))
window.styleMask = [.titled, .closable, .miniaturizable]
window.level = 1
window.title = "Test"
window.acceptsMouseMovedEvents = true
window.contentView = MainView()
window.center()
window.makeKeyAndOrderFront(window)
}
}
if #available(OSX 10.10, *){
let app = NSApplication.shared()
let appDelegate = AppDelegate()
app.delegate = appDelegate
app.run()
}
答案 0 :(得分:0)
您必须设置委托:
view.acceptsMouseMovedEvents = YES;