cursorUpdate
使用场景
方法签名
override func cursorUpdate(with event: NSEvent) {
// 在这里更新光标样式
}示例代码
import Cocoa
class CustomView: NSView {
override func cursorUpdate(with event: NSEvent) {
let mouseLocation = event.locationInWindow
// 检查鼠标位置并更新光标样式
if bounds.contains(mouseLocation) {
// 在视图内部,设置手形光标
NSCursor.pointingHand.set()
} else {
// 在视图外部,设置箭头光标
NSCursor.arrow.set()
}
// 触发光标更新事件
super.cursorUpdate(with: event)
}
}说明
Last updated