• <legend id='lRkR1'><style id='lRkR1'><dir id='lRkR1'><q id='lRkR1'></q></dir></style></legend>
    <i id='lRkR1'><tr id='lRkR1'><dt id='lRkR1'><q id='lRkR1'><span id='lRkR1'><b id='lRkR1'><form id='lRkR1'><ins id='lRkR1'></ins><ul id='lRkR1'></ul><sub id='lRkR1'></sub></form><legend id='lRkR1'></legend><bdo id='lRkR1'><pre id='lRkR1'><center id='lRkR1'></center></pre></bdo></b><th id='lRkR1'></th></span></q></dt></tr></i><div id='lRkR1'><tfoot id='lRkR1'></tfoot><dl id='lRkR1'><fieldset id='lRkR1'></fieldset></dl></div>
      1. <tfoot id='lRkR1'></tfoot>
      2. <small id='lRkR1'></small><noframes id='lRkR1'>

          <bdo id='lRkR1'></bdo><ul id='lRkR1'></ul>

      3. 在 iOS 14 小部件上渲染图像

        时间:2023-09-09
        <tfoot id='YXUkR'></tfoot>

            <tbody id='YXUkR'></tbody>
          <legend id='YXUkR'><style id='YXUkR'><dir id='YXUkR'><q id='YXUkR'></q></dir></style></legend>

          1. <i id='YXUkR'><tr id='YXUkR'><dt id='YXUkR'><q id='YXUkR'><span id='YXUkR'><b id='YXUkR'><form id='YXUkR'><ins id='YXUkR'></ins><ul id='YXUkR'></ul><sub id='YXUkR'></sub></form><legend id='YXUkR'></legend><bdo id='YXUkR'><pre id='YXUkR'><center id='YXUkR'></center></pre></bdo></b><th id='YXUkR'></th></span></q></dt></tr></i><div id='YXUkR'><tfoot id='YXUkR'></tfoot><dl id='YXUkR'><fieldset id='YXUkR'></fieldset></dl></div>

            <small id='YXUkR'></small><noframes id='YXUkR'>

              <bdo id='YXUkR'></bdo><ul id='YXUkR'></ul>
                • 本文介绍了在 iOS 14 小部件上渲染图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发 iOS 14 小部件扩展.

                  I'm developing a iOS 14 Widget extension.

                  我有 3 张图片要循环显示并创建一个时间线来显示这些图片.

                  I have 3 images to show in loop and creating a Timeline to show those images.

                  func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
                      var entries: [ImageEntry] = []
                      let currentDate = Date()
                      
                      for i in 1 ..< 4 {
                          let imageNumber = String(i)
                          let currentImage = "image_" + imageNumber
                          let entry = ImageEntry(date: currentDate,image: currentImage)
                          entries.append(entry)
                      }
                  
                      let nextUpdateDate = Calendar.current.date(byAdding: .minute, value: 5, to: currentDate)!
                      let timeline = Timeline(entries: entries, policy: .after(nextUpdateDate))
                  
                      completion(timeline)
                  }
                  
                  
                  struct WidgetModuleEntryView : View {
                  var entry: Provider.Entry
                  
                  var body: some View {
                      Image(entry.image)
                          .resizable()
                          .scaledToFill()
                      }
                  }
                  

                  始终呈现第一张图像,但不呈现后续图像.

                  First image always rendering but subsequent images are not.

                  可能是什么问题?

                  推荐答案

                  构建时间线需要为每个条目指定明确的条目日期.政策参数用于重新创建下一个时间线.

                  Constucting timeline you need to specify explicit entry date for each entry. The policy parameter is for recreating next timeline.

                  所以你的 getTimeline 应该看起来像

                  So your getTimeline should look like

                  func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
                      var entries: [ImageEntry] = []
                      let currentDate = Date()
                  
                      for i in 1 ..< 4 {
                          let imageNumber = String(i)
                          let currentImage = "image_" + imageNumber
                          let entryDate = Calendar.current.date(byAdding: .minute, value: (i-1)*5, to: currentDate)!
                          let entry = ImageEntry(date: entryDate, image: currentImage)
                          entries.append(entry)
                      }
                  
                      let timeline = Timeline(entries: entries, policy: .atEnd)
                      completion(timeline)
                  }
                  

                  这篇关于在 iOS 14 小部件上渲染图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 android home 小部件中获取 TextView 的文本(不在活动中)? 下一篇:主屏幕小部件上的 iOS 时钟动画

                  相关文章

                  <tfoot id='l06qS'></tfoot>

                  1. <legend id='l06qS'><style id='l06qS'><dir id='l06qS'><q id='l06qS'></q></dir></style></legend>

                    <small id='l06qS'></small><noframes id='l06qS'>

                      <bdo id='l06qS'></bdo><ul id='l06qS'></ul>
                    <i id='l06qS'><tr id='l06qS'><dt id='l06qS'><q id='l06qS'><span id='l06qS'><b id='l06qS'><form id='l06qS'><ins id='l06qS'></ins><ul id='l06qS'></ul><sub id='l06qS'></sub></form><legend id='l06qS'></legend><bdo id='l06qS'><pre id='l06qS'><center id='l06qS'></center></pre></bdo></b><th id='l06qS'></th></span></q></dt></tr></i><div id='l06qS'><tfoot id='l06qS'></tfoot><dl id='l06qS'><fieldset id='l06qS'></fieldset></dl></div>