tiantang
tiantang

Reputation: 526

NSScrollView one line at a time

I'm currently making a simple text editing program with Cocoa and Objective-C and I'm trying to make it scroll one line at a time with any type of scrolling.

I can make it scroll only one line by setting the setLineScroll parameter to the current line height for the NSScrollView. This only controls it when you press the arrows on the scroll bar. I would like to force it to only scroll one line at a time with both the arrows and the scroll wheel/track pad gestures.

If I subclass NSScrollView can I control this with the moveUp and moveDown methods for NSScrollView?

Thank you

Upvotes: 0

Views: 294

Answers (1)

Matt
Matt

Reputation: 63

You could override

- (void)scrollWheel:(NSEvent *)theEvent

, calculate the line height like you did for the setLineScroll method and scroll manually to the new scroll position.

You would probably need something like this

NSPoint currentPoint=[[scrollView contentView] bounds].origin;
currentPoint.y += _lineHeight
[[scrollView documentView] scrollPoint:currentPoint];

The sign will depend on the direction of the move.

Upvotes: 1

Related Questions