【问题标题】:Can I scroll WKInterfaceGroup programmatically?我可以以编程方式滚动 WKInterfaceGroup 吗?
【发布时间】:2015-05-29 17:10:57
【问题描述】:

我在 WKInterfaceGroup 中有一个带有长文本的标签和一个按钮。 我可以在按钮的触摸处理程序上将组滚动到顶部吗?

【问题讨论】:

    标签: ios swift watchkit apple-watch wkinterfacegroup


    【解决方案1】:

    您可以从 WatchOS 4 开始执行此操作。 WKInterfaceController 有一个功能。

    func scroll(to object: WKInterfaceObject, at scrollPosition: WKInterfaceScrollPosition, animated: Bool)
    

    只需指定您要滚动到的object(例如WKInterfaceGroup),并在它应该滚动到的屏幕上指定scrollPosition(在您的情况下为.top),然后您再好。所以在你的 WKInterfaceController 类中:

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

    Read more on this in the Apple Developer documentation for WKInterfaceController

    And the possible values for scrollPosition

    【讨论】:

    • 对我来说,它只有在我为组分配固定高度时才有效。如果整个屏幕具有匹配的内容大小,则它不起作用。它在文档中没有说明任何内容。我错过了什么吗?
    【解决方案2】:

    没有。使用 WatchKit 以编程方式滚动界面的唯一方法是滚动到 WKInterfaceTable 中的特定行。

    【讨论】:

      猜你喜欢
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多