代码之家  ›  专栏  ›  技术社区  ›  Alex Stone

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

  •  0
  • Alex Stone  · 技术社区  · 7 年前

    我的apple watch应用程序有一个复杂之处,我想添加第二个样式。我提出了一个非常基本的原型,但没有看到它可供选择的手表表面。所以我试图解决这个问题:

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

    CLKComplicationTemplateModularSmallRingText 有效的模板 ModularSmall 并发症类型?

        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

    0 回复  |  直到 7 年前
        1
  •  1
  •   Alex Stone    7 年前

    结果我被苹果的文件误导了。我需要使用Graphic(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