将GraphicCircular Apple Watch复杂功能添加到现有Xcode项目中

时间:2018-10-12 02:46:41

标签: swift xcode apple-watch watch-os apple-watch-complication

我在网上找不到任何文档来说明如何添加Watch Series 4上可用的任何新的“图形”复杂功能。这些是我的步骤:

(1)添加了符合CLKComplicationDataSource的类(下面的代码) (2)将并发症配置设置为指向(1)和“并发症”资产文件夹  enter image description here (4)从Sketch导出png并将其拖动到Complications资产文件夹中,以Modular / Utilitarian / Circular 复杂性资产文件夹中的图形(角,边框和圆形)占位符将不接受png(仅pdf)。enter image description here毕竟,旧的模块化实用程序和圆形并发症可以正常工作,但是图形的图像(pdf) (转角,边框和圆形)无法在设备enter image description here上呈现

import Foundation
import ClockKit

class HockeyTrackerComplication: NSObject, CLKComplicationDataSource {
    func getSupportedTimeTravelDirections(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimeTravelDirections) -> Void) {
        handler([])
    }

    func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
        if #available(watchOSApplicationExtension 5.0, *) {
            if complication.family == .circularSmall {

                let template = CLKComplicationTemplateCircularSmallRingImage()
                guard let image = UIImage(named: "Circular") else { handler(nil); return}
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

            } else if complication.family == .utilitarianSmall {

                let template = CLKComplicationTemplateUtilitarianSmallRingImage()
                guard let image = UIImage(named: "Utilitarian") else { handler(nil); return}
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

            } else if complication.family == .modularSmall {

                let template = CLKComplicationTemplateModularSmallRingImage()
                guard let image = UIImage(named: "Modular") else { handler(nil); return}
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

            } else if complication.family == .graphicCircular {
                let template = CLKComplicationTemplateGraphicCircularImage()
                guard let image = UIImage(named: "GraphicCircular") else { handler(nil); return}
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

            } else if complication.family == .graphicBezel {
                let template = CLKComplicationTemplateModularSmallRingImage()
                guard let image = UIImage(named: "GraphicBezel") else { handler(nil); return}
                template.imageProvider = CLKImageProvider(onePieceImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

            } else if complication.family == .graphicCorner {
                let template = CLKComplicationTemplateGraphicCornerCircularImage()
                guard let image = UIImage(named: "GraphicCorner") else { handler(nil); return}
                template.imageProvider = CLKFullColorImageProvider(fullColorImage: image)
                let timelineEntry = CLKComplicationTimelineEntry(date: Date(), complicationTemplate: template)
                handler(timelineEntry)

            } else {

                handler(nil)

            }
        } else {
            // Fallback on earlier versions
        }
    }



}

2 个答案:

答案 0 :(得分:1)

我的问题是我没有实现lists_to_delete = set(list_x) - set(list_y) https://developer.apple.com/documentation/clockkit/clkcomplicationdatasource/1650686-getlocalizablesampletemplate,尽管它被列为可选,并且不是实现x=0 n=input('What is the integer value of n? n= ') while (int(n)<=10000): n=(int(n))**(int(x)) x += 1 print(int(n)) 的必需方法的一部分,但使我的图像复杂化了。

答案 1 :(得分:0)

  1. 转换下一个:

    • UIImage名称:“ GraphicBezel”->“ Complication / GraphicBezel”
    • UIImage名称:“ GraphicCircular”->“ Complication / GraphicCircular”
    • UIImage名称:“ GraphicCorner”->“ Complication / GraphicCorner”
  2. 图像资产,配置图像集>屏幕宽度>单独宽度 并将图像设置为手表尺寸区域(38mm,40mm,42mm,44mm)。

适合我的情况。