Calin-Andrei Burloiu
Calin-Andrei Burloiu

Reputation: 1481

Pagination support in NSScrollView

I am trying to create a view on Mac OS where I would like to be able to scroll from page to page by using two finger swipe gestures on trackpad or mouse wheel scrolling. Is this functionality implemented in Cocoa?

I noticed that there is some pagination support in NSScrollView, but I don't know how to trigger it via swiping/scrolling. There is NSScrollView.pageScroll property, where the documentation states:

The value of this property is the amount of the document view kept visible when scrolling page by page, expressed in the content view’s coordinate system. This value is used when the user clicks the scroll arrows while holding down the Option key.

Unfortunately, the documentation is outdated, because newer versions of Mac OS no longer have scroll arrows in their UI, so there's anything you can click while holding the Option key. However, I discovered that this mechanism is now triggered if you click the scroll bar outside of the scroll position indicator.

If NSScrollView does not natively support pagination via swipes, I am thinking of a way to programmatically trigger the pagination mechanism described above. Do you know how this mechanism can be triggered? Using NSView.scrollPoint might not be the best idea because you lose the nice animation effects that come with the pagination mechanism.

Upvotes: 1

Views: 589

Answers (1)

Willeke
Willeke

Reputation: 15633

Scroll page down:

[scrollView pageDown:self];

Scroll page up:

[scrollView pageUp:self];

Upvotes: 3

Related Questions