开发中遇到的一些细节问题总结如下:
鼠标事件
- 功能键(如判断是否按下了command、shift、control、option键等)
override func mouseDown(with event: NSEvent) {
//获取鼠标点击位置坐标
let inWindowlocation = event.locationInWindow
//转化成视图的本地坐标
let inViewPoint = self.view.convert(inWindowlocation, to: nil)
print("inWindowlocation = \(inWindowlocation), \n inViewPoint = \(inViewPoint)")
//MARK: - 功能键处理
if event.modifierFlags.contains(.command) {
//是否按下了命令建
print("input command ...")
} else {
print("no input command ...")
}
super.mouseDown(with: event)
}