开发者

NSTextView's adjustScroll method

开发者 https://www.devze.com 2022-12-24 05:02 出处:网络
I\'m trying to implement typewriter scroll开发者_Python百科ing in my Cocoa text editor, keeping the insertion point centered vertically in its scrollview.

I'm trying to implement typewriter scroll开发者_Python百科ing in my Cocoa text editor, keeping the insertion point centered vertically in its scrollview.

Toward this end, I have subclassed NSClipView to provide a scrollToPointWithoutConstraint method, which scrolls the document to a specified point without calling constrainScrollPoint. This is necessary because for short documents the insertion point can't be centered unless we scroll beyond the document's bounds.

This seems reasonably straightforward so far and does what I want. The problem comes in when I try to scroll using the scroll bars. If I'm scrolled to the end of the document, such that part of the scroll view contains an area outside the document's bounds, trying to scroll up by a small increment causes the scroll view to jump, immediately clamping to the document's actual bounds.

I gather that I might need to subclass NSTextView and override the adjustScroll method; this is where my actual question begins. The proposedVisibleRect that is passed to adjustScroll already has its dimensions adjusted so that they lie within the document's actual bounds. Is there a way that I can change the value of proposedVisibleRect before adjustScroll is called? Alternatively, am I going about this entirely wrong? Any suggestions would be greatly appreciated at this point.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号