cocoa - Pinning NSScrollView's document view while resizing a window -


There is such a trivial question to ask, but it is bothering me for some time.

I have a window in which there is a scroll view. Usually, the scroll view has a document view that is vertically larger than the clip view, so you can see all the contents inside the scroll view. To get the vertical scroller.

When I change the size of the window, then I recalculate the size of the content in the document view of the scroll view (because the scroll view may be slim, which can make the height of the document necessary to grow ). One side effect, however, is that when the window size changes, the documentview clips the visible edge flush underneath the bottom edge of the clip (which ensures that the last line of the text is always visible). This is a strange effect, because usually, with the top edge of the window clips, the document view keeps the top view edge of the flush (i.e., the top row of text in the document view is pinned to the top).

So, to fix this problem, my initial idea was to just implement a windowDidResize: or windowWillResize: toSize: Note, notice the delta between the height of the old window frame and the new height, and Then just scroll the scroll view a lot to scroll the top row of the scroll view pinned to the top.

However, for some reason, it does not appear to be working almost works, but some resizing deltas begin to close a pixel, and if you press the window So fast, sometimes ~ 10 pixels are off, so the effect is that the top row of the scroll view is pinned to the top , but not enough, and it is distracting .

Is there a better way to do this? Here is the relevant code:

  - (zero) Windowodid resize: (nsnification *) notification; {If ([notification object] == ​​mainWindow) {CGFloat currentWindowHeight = [mainWindow frame] .size.height; // Previous WindowHeight a ivar NSNumber * heightDeltaNum = [NSW Number with number FLOWAT: (Current WindowHeight - Previous WindowHeight)]; Previous WindowHeight = currentWindowHeight; [[NSNotificationCenter defaultCenter] postNotificationName: @ "AFSNSCSCView" Object: AltitudeTM]; }} - (zero) snapcrollview notice: (nsnification *) information; {[Self snapcroll view]; NSNumber * heightDiltaNen = [information object]; CGFloat newY = [[Tagcrollview document view] visual transit] .origin.y - [heightDeltaNum floatValue]; NSPoint Point ToScroll = NSMakePoint (0, newY); [[Tagcrollview documentview] scrollpoint: pointsococcal]; } - (zero) snapScrollView; {[...] // Adjust the scene frame [[tag scrollview document view] setframe: nsmkract (0, 0, existing documentframe.eight., Newdocumentvoice)]; [...]}  

Your document view needs to be overridden - (BOOL) IsFlipped method and return yes.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -