【发布时间】:2021-06-22 10:27:32
【问题描述】:
我有一个包含 10 个事件的数组,假设当前时间是上午 10 点,事件将在上午 11 点开始。 每个事件30分钟,两个事件之间的间隔是30分钟。
现在,我能够正确显示表盘上的所有必需信息,即启动表盘时,它会显示下一个事件是在上午 11 点,当第一个事件在上午 11:30 完成时,上午 11:31 表盘显示下一个活动将于下午 12 点开始。
我能够成功地完成这一切。
当我想在开始时间前 15 分钟显示第一个事件的提醒时,我遇到了问题。
例如,如果一天中的第一个事件将在上午 11 点开始,那么表盘将仅在上午 10:45 而不是上午 10:45 之前显示第一个事件的提醒。
另外,当一天的最后一个活动结束时,如何移除并发症?
我浏览了 Complications WWDC - 2015 的视频。
我正在尝试在 CLKComplicationTemplateModularLargeStandardBody 上显示复杂功能。
private func getTimeLineEntry() -> Date {
if shouldShowCountDown {
return startDate.addingTimeInterval(-15 * 60)
} else {
return startDate
}
}
func getCurrentTimelineEntry(for complication: CLKComplication, withHandler handler: @escaping (CLKComplicationTimelineEntry?) -> Void) {
// Call the handler with the current timeline entry
let headerTextProvider = CLKSimpleTextProvider(text: "Complication Updates")
let body1 = "My Title"
let body1TextProvider = CLKSimpleTextProvider(text: body1)
let body2TextProvider = CLKSimpleTextProvider(text: "My Subtitle")
let template = CLKComplicationTemplateModularLargeStandardBody(headerTextProvider: headerTextProvider, body1TextProvider: body1TextProvider, body2TextProvider: body2TextProvider)
let entry = CLKComplicationTimelineEntry(date: getTimeLineEntry(), complicationTemplate: template)
handler(entry)
}
在这里,startDate 是上午 11 点,我想在活动开始前 15 分钟(即上午 10:45)显示复杂功能的提醒。我使用了一个布尔变量来决定当前时间是否是 startDate > Current Date。如果是,则在 15 分钟前显示倒计时。
【问题讨论】:
-
您无法移除并发症;您只需要显示“没有更多事件”之类的消息即可。对于事件开始时间,您只需要指定时间线条目的正确时间以及在此之前显示的内容;某种类型的空状态。
-
@Paulw11,感谢您的回复。我在这里添加我的代码,请让我知道我的代码中缺少什么。
-
我无法确切告诉您要添加什么,但在
getCurrentTimelineEntry中,您可以根据是否有当前或即将发生的事件来更改并发症的内容。您还可以使用this method 为您的时间线提供一系列条目 -
嗨@Paulw11,感谢您的帮助和指导,我现在可以根据我的要求显示并发症。我所要做的就是在第一次活动时显示空模板。
标签: ios swift apple-watch watchos apple-watch-complication