您捕获相应的mouseDown事件
原文链接:https://www.f2er.com/swift/319291.htmlimport Cocoa class MyView : NSView { override func mouseDown(theEvent : NSEvent) { println("left mouse") } override func rightMouseDown(theEvent : NSEvent) { println("right mouse") } }
请参阅NSResponder以获得更多魔力.
斯威夫特4
import Cocoa class MyView : NSView { override func mouseDown(with theEvent: NSEvent) { print("left mouse") } override func rightMouseDown(with theEvent: NSEvent) { print("right mouse") } }