3

I have an NSView embedded inside a NSScrollView.

When changing the magnification in my app I'm changing the view's frame by adjusting the constraints and calling layoutSubtree:.

Now I'd like to center the same area of the view after changing the embedded view's size.

The following bits of code should be doing the trick -
the scrollers actually look updated, i.e. they expand and stick to the same position. However the scroll view doesn't seem to know about the changed position.

When starting to scroll the (updated) view manually the scroll bar positions 'jump' from the position changed via code to the actual position that's reflecting the view's scroll position.

It feels like the inverse of reflectScrolledClipView: is required after setting the scrollers via code..

Pseudocode:

 double hScrollPos = NSScrollView.horizontalScroller.doubleValue;
 double vScrollPos = NSScrollView.verticalScroller.doubleValue;

 [view updateFrameSizeAndStuff];
 [view invalidateIntrinsicContentSize];

 // this seems to early though:
 NSScrollView.horizontalScroller.doubleValue = hScrollPos;
 NSScrollView.verticalScroller.doubleValue = vScrollPos;
cacau
  • 3,606
  • 3
  • 21
  • 42
  • Are you overriding intrinsicContentSize to return the new size? – geowar Feb 18 '15 at 21:23
  • Am now, thanks for the heads up. Question updated accordingly - doesn't help, though. The scrollers look updated, positioned OK, but doesn't reflect back to the actual scrollview and scrolled content. As if the scrollers don't propagate the changed value back to the scroller..? – cacau Feb 24 '15 at 07:00
  • WAG: [self autoscroll:theEvent]; ? – geowar Feb 26 '15 at 16:08
  • FWIW - did it the hard way (manually, calculating offsets, etc.). Would have been nice to just use the one-liner mentioned above, though... – cacau May 28 '15 at 07:58

0 Answers0