Thanks for all your replies, Martin and Paul. Martin, I tried the " [NSTextView scrollRangeToVisible:] with NSMakeRange(0,0) ", but it is the same as to use [scrollPoint:] solely. Only with [glyphRangeForTextContainer:] in prior the scroll-to-top works. I don't think it is the problem of coordinate system flip-ness, because when using [scrollPoint:] without [glyphRangeForTextContainer:], the text view does not always scroll to bottom, either, it just does not always scroll to top under certain window size and text length. And it seems not solely [glyphRangeForTextContainer:] triggers the scroll-to-top because without [scrollPoint:] the scrolling does not work, either.
Another minor wired problem is the trick of using both [glyphRangeForTextContainer:] and [scrollPoint:] works only when you drag-drop a NSScrollView in IB and then set the embedded custom view as NSTextView. If an NSTextView is dragged and dropped directly (and IB automatically embed it in a NSScrollView), the scroll-to-top does not work even with the trick (and I haven't found a trick to make it work under such situation). Regards, Dong 在 2010年6月8日 上午5:29,Martin Wierschin <mar...@nisus.com>写道: > On 2010.06.07, at 2:10 PM, Paul Sanders wrote: > > 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. >> > > You're right about triggering layout, but there's no reason the text system > should have any trouble with NSMakePoint(0,0). NSTextView and the Cocoa > layout system always use a flipped coordinate system, so the origin is > always top-left. > > Perhaps the problem is that once layout completes (or during layout), you > (or Cocoa) is automatically scrolling the text view somewhere else? I'd > break in the debugger to see if anything else is triggering unwanted > scrolling. > > ~Martin > > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com