滚动 WKInterfaceController 回到顶部

Scroll WKInterfaceController back to top

我当前显示的是一长串文本标签,下方还有一个按钮,用于转到 'next' 消息。

当按下下一个按钮时,由于手表套件奇怪的自动调整大小机制,标签会自动调整其高度;但是屏幕不会改变位置。每当标签更新时,我想将 InterfaceController 滚动回顶部。这在当前的 Watch Kit SDK 中可行吗?

一位 Apple 员工说

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! :)

在开发者论坛上 https://devforums.apple.com/message/1074525#1074525

目前,界面控制器没有API滚动到顶部。但我做了同样的解决方法。

  1. 在顶部添加一个 WKInterfaceTable。
  2. 将行控制器组的高度设置为 2 并设置 背景颜色为黑色。
  3. 将行数设置为 1。
  4. 调用以下方法。

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

这在 watchOS 4 中是可能的。只需使用 scrollToObject:atScrollPosition:animated: 方法。