Render Images on iOS 14 Widgets

前端 未结 1 780
無奈伤痛
無奈伤痛 2021-01-26 23:30

I\'m developing a iOS 14 Widget extension.

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

func getTimeline(in context: Conte         


        
相关标签:
1条回答
  • 2021-01-27 00:12

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

    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)
    }
    
    0 讨论(0)
提交回复
热议问题