cursorUpdate
调用时机
示例代码
import Cocoa
class CustomView: NSView {
override func cursorUpdate(with event: NSEvent) {
// 处理光标更新事件
let mouseLocation = event.locationInWindow
// 根据鼠标位置决定光标样式
if mouseLocation.x < bounds.midX {
NSCursor.pointingHand.set() // 左侧使用手形光标
} else {
NSCursor.arrow.set() // 右侧使用箭头光标
}
}
override func acceptsFirstResponder() -> Bool {
return true // 确保视图可以接收输入事件
}
}说明
注意事项
Last updated