0

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:

Issue

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.

Mark
  • 6,647
  • 1
  • 45
  • 88
  • Where in the view hierarchy is the text field? What is the question? – Willeke Mar 08 '18 at 12:44
  • I experimented with different placements of the text field, it does not matter where I place it to cause the issue. The problem is that drawRect: is called each time the input caret is drawn (it flashes on & off). – Mark Mar 08 '18 at 19:46
  • The answer to the linked question uses an override of `hitTest:` to log, it doesn't do anything. "So it looks like the response to hitTest defines what views will get redrawn.". Why is calling `drawRect:` a problem? – Willeke Mar 09 '18 at 08:52
  • I added a GIF showing the issue. I don't understand why an unrelated view is redrawn when the cursor blinks. Maybe a side-effect of the visual effect view or scroll view? – Mark Mar 09 '18 at 15:07
  • According to the linked question, it is a quirk of the blinking cursor. – Willeke Mar 09 '18 at 16:58

0 Answers0