【问题标题】:WatchKit 2 Complication Text Only Shows Up in PreviewWatchKit 2 并发症文本仅在预览中显示
【发布时间】:2015-09-07 17:04:47
【问题描述】:

我正在尝试为2 开发一个非常简单的复杂功能,它通过简单的文本提供程序说“嗨”。

我设法实现了一些奇怪的行为;单击复杂功能或从自定义表盘屏幕预览时,我可以看到文本,但在显示表盘时看不到。看看:

任何想法可能导致这种情况?

我的文本提供程序如下所示

var textProvider: CLKSimpleTextProvider

override init() {

    textProvider = CLKSimpleTextProvider()
    textProvider.text = "Hi"
    textProvider.shortText = "HI"
    textProvider.tintColor = UIColor.whiteColor()
    super.init()
}

我得到的getPlaceholderTemplateForComplication 看起来像

func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {
    // This method will be called once per supported complication, and the results will be cached

     switch complication.family {
     case .ModularSmall:
        let stemplate = CLKComplicationTemplateModularSmallSimpleText()
        stemplate.tintColor = UIColor.whiteColor()
        stemplate.textProvider = textProvider
        handler(stemplate)
     case .CircularSmall:
        let stemplate = CLKComplicationTemplateCircularSmallSimpleText()
        stemplate.tintColor = UIColor.whiteColor()
        stemplate.textProvider = textProvider
        handler(stemplate)
     default:
        handler(nil)
    }

}

【问题讨论】:

    标签: watchkit swift watchkit apple-watch apple-watch-complication


    【解决方案1】:

    在自定义表盘时,Apple Watches 会调用 getPlaceholderTemplateForComplication:withHandler: 来显示占位符文本。既然你已经实现了它 - 你可以看到“嗨”。太棒了。 但是当表盘显示时,它会调用另一个方法,例如:

    • getCurrentTimelineEntryForComplication:withHandler:
    • getTimelineEntriesForComplication:beforeDate:limit:withHandler:
    • getTimelineEntriesForComplication:afterDate:limit:withHandler:

    而且您似乎没有实施它们。因此,实施这些方法将解决您的问题。 您可以在此 WWDC 2015 教程中找到有关这些方法的更多详细信息:https://developer.apple.com/videos/wwdc/2015/?id=209

    【讨论】:

      猜你喜欢
      • 2022-11-14
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      相关资源
      最近更新 更多