I have a custom control. If it inherits from NSView
, it automatically becomes the first responder when I click on it. If it inherits from NSControl
, it does not. This difference in behavior persists, even if I override mouseDown(with:)
and don't call super.
Code:
class MyControl: NSView {
override var canBecomeKeyView: Bool { return true }
override var acceptsFirstResponder: Bool { return true }
override func drawFocusRingMask() { bounds.fill() }
override var focusRingMaskBounds: NSRect { return bounds }
override func draw(_ dirtyRect: NSRect) {
NSColor.white.set()
bounds.fill()
}
}
As you can see, I override acceptsFirstResponder
among other methods and properties that are key view and responder related. I have also checked the refusesFirstResponder
property. It is set to false.
- What is the reason for this difference in behavior?
- Is there a method or property that I can override to influence it?
- Say I want the behavior where the view becomes the first responder when clicked and the view inherits from
NSControl
, is callingwindow!.makeFirstResponder(self)
at the beginning of my mouse-down event handler a good solution or is there a better one?