iOS WatchOS5 - 如何为手表应用程序支持多个复杂系列?

问题描述 投票:0回答:1

我有一个复杂的工作我的苹果手表应用程序,我想添加第二种风格。我提出了一个非常基本的原型,但是看不到它可以在表盘上进行选择。所以我正在尝试解决这个问题:

我的应用程序可以支持多个并发症吗?我可以在表盘上同时运行两个并发症吗? (或者它是或者是或者如果我有一个,iOS不会显示第二个?)我尝试添加一个新的表盘,但它不允许我。

CLKComplicationTemplateModularSmallRingTextModularSmall类型并发症的有效模板吗?

    func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {

        if complication.family == .modularSmall {
            let template = CLKComplicationTemplateModularSmallRingText()
            template.ringStyle = .open
            template.fillFraction = 0.3

            let testProvider = CLKSimpleTextProvider(text: "TST", shortText: "S")
            sleep.tintColor = UIColor.green
            template.textProvider = testProvider
            template.tintColor = UIColor.green

            let entry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)

            // Pass the entry to ClockKit.
            handler(entry)
        }
        else if complication.family == .graphicRectangular {
            let template = CLKComplicationTemplateGraphicRectangularLargeImage()
//this complication works...
}

占位符模板现在是相同的:

func getPlaceholderTemplate(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTemplate?) -> Void) {

    // Pass the template to ClockKit.
    if complication.family == .modularSmall {
        let template = CLKComplicationTemplateModularSmallRingText()
//...

Complication supported families

我在并发症占位符文件中看到一个错误(但我正在44毫米设备上测试) - 将修复它并查看发生了什么。我是否为模块化复杂功能返回了错误的图像或错误的模板类型?我想要一个圆环规

enter image description here

ios swift apple-watch apple-watch-complication watch-os-5
1个回答
0
投票

事实证明我被Apple的文档误导了。我需要使用GraphicCircular复杂功能(WatchOS5中的新功能)而不是模块化(旧表盘)

func circularTemplate() -> CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText{
    let template = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText()
    let gauge = CLKSimpleGaugeProvider(style: .ring, gaugeColor: UIColor.green), fillFraction: 0.3)
    template.gaugeProvider = gauge

    let random = arc4random() % 999

    let middle = CLKSimpleTextProvider(text: "4.5", shortText: "4")
    middle.tintColor = kRGBColorFromHex(0x657585)
    template.tintColor = kRGBColorFromHex(0x657585)
    template.centerTextProvider = middle

    let bottom = CLKSimpleTextProvider(text: "-\(random)", shortText: "1..")
    template.bottomTextProvider = bottom
    return template
}

新风格:

enter image description here

旧式:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.