I'm running into the strangest issue:
I have a Cocoa app with a custom NSView inside an NSScrollView.
When I click into the text field, drawRect:
is called on my custom view each time the cursor blinks.
If I move my custom view outside of the scroll view, the issue goes away. Also if I place my test view at the very bottom of its parent view, the issue goes away.
This is not a duplicate of Why does the blinking cursor in textfield cause drawRect to be called?, it's the same issue, but I did not override hitTest:
. In fact, my test view implementation looks like this:
class TestView:NSView
{
override func draw(_ dirtyRect: NSRect) {
NSColor.red.set()
dirtyRect.fill()
logWarning("drawRect in custom view called. dirty rect: \(NSStringFromRect(dirtyRect))")
}
}
My view hierarchy:
NSWindow
NSSplitView
NSView
NSVisualEffectView
NSTabView
NSView
NSScrollView
NSView
TestView
It seems to be a combination of the NSVisualEffectView and NSScrollView. I can't reproduce this in a fresh project. I tried reshuffling views in my existing app, but I can't pin this down.
The issue in action:
Note how drawRect:
is called as soon as the text field has focus and stops when I click outside. I don't see why an unrelated view has to be redrawn with each caret pulse.