Reputation: 768
I'm making a setup view controller that embeds other view controllers inside of it. I'm kinda making my own page control like on iOS.
My question is: if I have my NSScrollView outlet set up (BTW everything is working and I can scroll with the trackpad), how can I make it so when I click a button it sets the scroll view to a specific point?
I've tried a few things and had a google but it all relates to Objective-C and other weird non-XCode related things.
I imagine it would be something like iOS, which is (off the top of my head)
scrollView.contentOffset.y = CGPointMake(0.0,500)
Upvotes: 3
Views: 2058
Reputation: 385600
The Scroll View Programming Guide for Mac says this:
Two
NSView
methods support scrolling to reveal a specific location:scrollPoint:
andscrollRectToVisible:
. These high-level methods scroll the specified point or rectangle to the origin of the content view. You send these methods to the scroll view's document view or to one of its descendants. Scroll messages are passed up through the view hierarchy to the nearest enclosingNSClipView
instance.
So the direct equivalent of your iOS code would be
contentView.scrollPoint(CGPointMake(0, 500))
Note that you send the message to the content view, not the scroll view.
Upvotes: 7