0

this is going to be hard to explain. I am modifying the InfoBarStackView sample code from Apple. The problem that I am encountering, is that it looks as if one of the subviews is being divided in two, by NSStackview and rendered separately.

In my sample, I am adding 4 subviews to my stack view, each exactly the same size (and same code). This is then placed into an NSScrollView. (The layout is vertical.)

When the application is run, I see the very first two subviews. When I scroll downward, the weirdness begins. The subsequent view is rendered, where the bottom portion is rendered, then the top is rendered. If the vertical size is 272 pixels, the bottom is rendered as 256 pixels and the top is the remainder (16). Scrolling down to the last view causes the same problem.

Attached are some screen grabs to illustrate: NSViews in NSStackView upon startup..

NSViews in NSStackView are chopped into two..

I have a sample project for Xcode 8. I have posted the Xcode 8 project here, if someone would like to take a look. I can't seem to figure this one out.

2 Answers2

2

Are you referring to the extra bounding boxes that intersect the "Label" and "Show" buttons?

If you use Xcode's View Debugger to look at the decomposition of the view hierarchy and the drawn contents of each view, you'll see that the extra bounding boxes are drawn by the GT_BorderedViews — that is, the bottom GT_BorderedViews are each drawing two bounding boxes.

GT_BorderedView's implementation of -drawRect: calculates and draws the bounding boxes based on the dirtyRect that is passed in. However, as the documentation states, the dirty rect is «a rectangle defining the portion of the view that requires redrawing», not necessarily the entire bounds of the view. Changing the implementation to calculate and draw the border based on [self bounds] instead of the dirty rect results in the expected appearance.

Taylor
  • 3,183
  • 17
  • 18
  • Thanks! You are exactly right. I completely missed the fact that dirtyRect didn't draw the entire view. `[self bounds]` solves the problem. – Bob-GlueTools May 17 '17 at 00:01
-1

Taylor nailed it. I didn't realize that drawRect didn't render the whole view. Using [self bounds] rather than dirtyRect ensures the draw happens properly.