Reputation: 51
I have a setup that allows vertical scrolling to show some additional buttons. Upon clicking one of these, I'd like to snap the view back to it's initial (pre-scrolled) appearance.
I do not see any equivalent to UITableView.scrollRectToVisible in the Watchkit sdk.
Upvotes: 1
Views: 1266
Reputation: 31
You can use
func scroll(to object: WKInterfaceObject, at scrollPosition: WKInterfaceScrollPosition, animated: Bool)
as of WatchOS 4. Documentation
Upvotes: 2
Reputation: 46
There is no way to do that at this time, I'm afraid. The only WatchKit element capable of scrollTo: is, as Mike Swanson mentioned, the WKInterfaceTable
element. And even then, you can only scroll to make a cell visible, not to any specified offset.
Even if you hack something together where you nest your whole UI in a single WKInterfaceTable
cell, you still will not be able to achieve the behavior you desire, as it will only ever scroll so far as to have the bottom edge of the cell align with the bottom edge of the screen, with the rest spilling up and off the top.
Upvotes: 0
Reputation: 3347
The closest you'll get is the scrollToRowAtIndex:
method on WKInterfaceTable
(documentation). In your case, you can simply scroll to row 0.
Upvotes: 2