Mac osx 开发-Swift-NSView右键事件
2017-04-21 本文已影响144人
Funcy1Day
重写NSView的右键点击函数:
override func rightMouseDown(with event: NSEvent) {
let location = self.convert(event.locationInWindow, to: nil)
self.menu?.popUp(positioning: nil, at: location, in: self)
}
可以通过xib、代码等创建的NSMenu和自定义NSView的menu进行关联:
view.menu = rightMenu //rightMenu是作为右键事件弹出的菜单