我正在尝试开发一个非常简单的复杂功能watchkit2 从一个简单的文本提供者那里说“Hi”。
我设法实现了一些奇怪的行为;单击复杂功能或从自定义表盘屏幕预览文本时,我可以看到文本,但在显示表盘时看不到文本。看一看:
有什么想法可能导致这种情况吗?
我的文本提供程序看起来像这样
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)
}
}
自定义表盘时,Apple Watch 会调用getPlaceholderTemplateForComplication:withHandler:
显示占位符文本。既然你已经实现了它 - 你可以看到“Hi”。太棒了。
但是当表盘显示时,它会调用另一个方法,例如:
getCurrentTimelineEntryForComplication:withHandler:
getTimelineEntriesForComplication:beforeDate:limit:withHandler:
getTimelineEntriesForComplication:afterDate:limit:withHandler:
看来你还没有实现它们。因此,实施这些方法将解决您的问题。
您可以在 WWDC 2015 教程中找到有关这些方法的更多详细信息:https://developer.apple.com/videos/wwdc/2015/?id=209
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)