문제는 실제로 컨트롤을 첫 번째 응답자로 설정하지 않았기 때문일 수 있습니다. 간단히 클릭하면 자동으로 실행되지 않습니다. 다음은 첫 번째 응답자 상태를 받아들이는 빠른 클릭 예입니다 (너무 클릭하면됩니다). 그리고 포커스 링을 그립니다. 제어 기능을 활성화하고 목표와 동작을 설정하십시오.
class MyControl: NSControl {
override var acceptsFirstResponder: Bool {
return true
}
override func becomeFirstResponder() -> Bool {
return true
}
override func mouseDown(with event: NSEvent) {
window?.makeFirstResponder(self)
}
override func mouseUp(with event: NSEvent) {
if let action = action {
NSApp.sendAction(action, to: target, from: self)
}
}
override func draw(_ dirtyRect: NSRect) {
NSColor.white.set()
NSBezierPath(roundedRect: bounds.insetBy(dx: 1, dy: 1), xRadius: 3, yRadius: 3).fill()
if window?.firstResponder == self {
NSColor.keyboardFocusIndicatorColor.set()
} else {
NSColor.black.set()
}
NSBezierPath(roundedRect: bounds.insetBy(dx: 1, dy: 1), xRadius: 3, yRadius: 3).stroke()
}
override var focusRingMaskBounds: NSRect {
return bounds.insetBy(dx: 1, dy: 1)
}
override func drawFocusRingMask() {
NSBezierPath(roundedRect: bounds.insetBy(dx: 1, dy: 1), xRadius: 3, yRadius: 3).fill()
}
}
알아 냈습니까? 나는 똑같은 일을 처리하려고 노력하고있다. 감사. – pizzafilms
아니요, 절대로 - 다른 일을하기 위해 옆으로 치우고 아직 돌아 오지 않았습니다. – starkos
몇 가지 코드를 보여 주시겠습니까? – rocky