WatchKit 2 复杂文本仅显示在预览中 [英] WatchKit 2 Complication Text Only Shows Up in Preview

查看:19
本文介绍了WatchKit 2 复杂文本仅显示在预览中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为

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

我的文本提供者看起来像这样

var textProvider: CLKSimpleTextProvider覆盖初始化(){textProvider = CLKSimpleTextProvider()textProvider.text = "嗨"textProvider.shortText = "你好"textProvider.tintColor = UIColor.whiteColor()超级初始化()}

我得到的 getPlaceholderTemplateForComplication 看起来像

func getPlaceholderTemplateForComplication(complication: CLKComplication, withHandler handler: (CLKComplicationTemplate?) -> Void) {//每个支持的复杂功能将调用此方法一次,并将结果缓存开关complication.family {案例.ModularSmall:让 stemplate = CLKComplicationTemplateModularSmallSimpleText()stemplate.tintColor = UIColor.whiteColor()stemplate.textProvider = textProvider处理程序(模板)案例.CircularSmall:让 stemplate = CLKComplicationTemplateCircularSmallSimpleText()stemplate.tintColor = UIColor.whiteColor()stemplate.textProvider = textProvider处理程序(模板)默认:处理程序(无)}}

解决方案

在自定义表盘时,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

I'm trying to develop a very simple complication for 2 that says "Hi" from a simple text provider.

I've managed to achieve some strange behavior; I can see the text when the complication is clicked or when you are previewing it from the customize watchface screen, but not when the watchface is displayed. Have a look:

Any ideas what might be causing this?

My text provider looks like this

var textProvider: CLKSimpleTextProvider

override init() {

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

And my get getPlaceholderTemplateForComplication looks like

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)
    }

}

解决方案

While customizing watch face, Apple Watches calls getPlaceholderTemplateForComplication:withHandler: to show placeholder text. Since you've implemented it - you can see "Hi". That is cool. But when watch face displayed, it calls another methods, such as:

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

And it seems like you're not implemented them. So implementing these method will resolve your issue. You can find more detailed information about these methods in this WWDC 2015 Tutorial: https://developer.apple.com/videos/wwdc/2015/?id=209

这篇关于WatchKit 2 复杂文本仅显示在预览中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆