【问题标题】:Complication Image is White Box - watchOS 2 ClockKit并发症图像是白框 - watchOS 2 ClockKit
【发布时间】:2015-12-02 05:18:13
【问题描述】:

我正在尝试让图像显示为 Apple Watch 表盘上的复杂功能。我已经尝试过 .jpg 和 .png 文件。我相信使复杂功能工作的代码是正确的,但由于某种原因,图像会像这样变成白色:

我的代码如下:

var template: CLKComplicationTemplate? = nil

let temporaryTemplate = CLKComplicationTemplateModularSmallSimpleImage()
let theImage = UIImage(named: "testImage")!.imageWithRenderingMode(.AlwaysTemplate)

let imager = CLKImageProvider(onePieceImage: theImage)
temporaryTemplate.imageProvider = imager

template = temporaryTemplate

我知道这些图像被视为“仅限 alpha”的并发症,但我认为这是由系统自动完成的。我在这里错过了一步吗?

【问题讨论】:

    标签: ios swift apple-watch watchos-2


    【解决方案1】:

    你是对的,你的代码一切都是正确的,证据是白色方块,这意味着问题在图像中。

    从 12:10 开始,请仔细观看the video。简而言之,您必须使用 alpha 通道创建单色 png 图像,系统当然无法为您完成。下面是例子,你可以把它代替你的图片看看结果:

    另外请附上您的图片以查看。

    【讨论】:

      【解决方案2】:

      我使用了指南中提到的复杂功能的图像。下面是我的代码。它对我来说很好,删除渲染模式部分并尝试。我附上了一张我使用的示例图片。

          let template = CLKComplicationTemplateModularLargeStandardBody()
          let image = UIImage(named: imageName[![enter image description here][1]][1])
      
          template.headerImageProvider =
              CLKImageProvider(onePieceImage: image!)
          template.headerTextProvider = CLKSimpleTextProvider(text: headerText)
      

      【讨论】:

      • 很好,但是我使用的图像呢?为什么这些图像不特别有效?
      • 是的,问题出在图像上,系统不会对图像进行任何修改。仅使用带有 alpha 通道的单色图像。通过此链接获取复杂图像指南以获取更多信息developer.apple.com/watch/human-interface-guidelines/…
      【解决方案3】:

      我承认我不会看 WWDC 视频或阅读 Apple 文档... 我尝试了一些东西,它通常有效。

      所以在看到这个错误并使用图像后,我有了一个成功的想法。即使我不支持前进或后退,我也必须返回时间线条目。

      解决了应用图标出现白框图片的问题。

      - (void)getCurrentTimelineEntryForComplication:(CLKComplication *)complication
                                     withHandler:(void(^)(CLKComplicationTimelineEntry * __nullable))handler {
      [self getLocalizableSampleTemplateForComplication:complication
                                            withHandler:^(CLKComplicationTemplate * _Nullable complicationTemplate) {
                                                CLKComplicationTimelineEntry* entry = [CLKComplicationTimelineEntry entryWithDate:[NSDate date]
                                                                                                             complicationTemplate:complicationTemplate];
                                                handler(entry);
                                            }];}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-08
        • 2018-09-12
        • 2022-12-09
        • 2022-11-05
        • 1970-01-01
        相关资源
        最近更新 更多