Re: Scrolling Behavior of NSTextView
Re: Scrolling Behavior of NSTextView
- Subject: Re: Scrolling Behavior of NSTextView
- From: "Paul Sanders" <email@hidden>
- Date: Mon, 7 Jun 2010 22:10:58 +0100
> I encountered a wired behavior of NSTextView. I tried to use the following statement to scroll to top:
> [[_scrollView documentView] scrollPoint:NSMakePoint(0, 0)];
>
> where the *documentView* is a NSTextView. But it seems when the window is in
> certain size, the scroll-to-top behavior does not take effect. Then I added
> a seemingly irrelevant statement before the above statement, by accidental,
> so the fragment become the follows:
>
> [[[_scrollView documentView] layoutManager] glyphRangeForTextContainer:[[self dictionaryContent] textContainer]];
> [[_scrollView documentView] scrollPoint:NSMakePoint(0, 0)];
>
> The complete source code is at http://techsingular.net/dict_mac/dict_mac.dmg
>
> The problem happens when you search for "灵" or "神" through this dictionary program.
I haven't looked at your code so I don't know what is going on in detail but [NSLayoutManager glyphRangeForTextContainer:] performs layout, if it hasn't been done already, which is probably why it is affecting the results you get. Until layout has been performed, the Cocoa text system doesn't know the size of the text (in terms of the amount of space it will take up on the display) and so (I surmise) scrollPoint: doesn't work as expected.
In other words, the code you have now is correct.
Regards,
Paul Sanders.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden