Msencenb
Msencenb

Reputation: 5104

Scroll WKInterfaceController back to top

I'm currently displaying a long label of text plus a button below it to go to the 'next' message.

When the next button is pressed the label adjusts it's height automagically thanks to watch kit's strange auto sizing mechanisms; however the screen does not change positions. I want to scroll the InterfaceController back to the top whenever the label updates. Is this possible with the current Watch Kit SDK?

Upvotes: 2

Views: 1254

Answers (4)

RichApple
RichApple

Reputation: 3

Swift 5.0 ... this works for me:

where this call is

  1. inside the WKInterfaceController class of the WatchKit Extension app,

  2. my 'btnPrevTee' is a button located at the top of the watch face

    scroll(to:btnPrevTee, at:.top, animated:true)

ref: https://developer.apple.com/documentation/watchkit/wkinterfacecontroller/2874208-scroll

Upvotes: 0

bmueller
bmueller

Reputation: 2701

This is now possible in watchOS 4. Just use the scrollToObject:atScrollPosition:animated: method.

Upvotes: 2

Parth Adroja
Parth Adroja

Reputation: 13514

Currently, there is no API for the interface controller to scroll to top. But I did a workaround for the same.

  1. Add a WKInterfaceTable to the top.
  2. Set the Height of the Row Controllers Group to 2 and set the background color to black.
  3. Set the number of rows to 1.
  4. Call the below method.

func scrollInterfaceToTop() { tableView.setHidden(false) tableView.scrollToRow(at: 0) tableView.setHidden(true) }

Upvotes: 0

Stephen Johnson
Stephen Johnson

Reputation: 5121

An Apple employee said

Scrolling to the top is only supported on WKInterfaceTable. If you'd like this functionality on a WKInterfaceController, please file a request for it at https://bugreport.apple.com. Thanks! :)

on the developer forums https://devforums.apple.com/message/1074525#1074525

Upvotes: 1

Related Questions