Mac osx 开发-Swift-NSView右键事件

重写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是作为右键事件弹出的菜单

你可能感兴趣的:(Mac osx 开发-Swift-NSView右键事件)